Sorry for boring you again
I use you suggestion to run js and get the js result in ProcessHandler_OnCustomMessage,but when I send the result string to memo in form ,noting append! What's wrong?
the demo code here:
procedure ProcessHandler_OnCustomMessage(const browser: ICefBrowser;
sourceProcess: TCefProcessId; const ProMsg: ICefProcessMessage);
var
JsCallStr, JsResultStr: string;
FrameID: NativeInt;
TempFrame: ICefFrame;
val: ICefV8Value;
context: ICefv8Context;
excp: ICefV8Exception;
begin
JsCallStr := ProMsg.ArgumentList.GetString(0);
FrameID := ProMsg.ArgumentList.GetInt(1);
if (browser <> nil) then
begin
if FrameID = -1 then
TempFrame := browser.MainFrame
else
TempFrame := browser.GetFrameByident(FrameID);
if (TempFrame <> nil) then
begin
context := TempFrame.GetV8Context;
context.Eval(JsCallStr, TempFrame.Url, 0, val, excp);
JsResultStr := val.GetStringValue;
// Application.MessageBox(PChar(JsResultStr), '', MB_OK);---> this could work perfectly!
// Workers.Signal('#JsResultReturn', TQJobExtData.Create(JsResultStr), -->this not work at all ,another method use globalvar outside the funtion are also not work too!
// jdfFreeAsObject);
end;
end;
end;
Also Another question is , If the ICefFrame is not mainfrain,The JsCode will let the page go blank! it's so strange to me....
btw:the jsCallStr is " $(document.body).html() "
Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
How to Get Js Result outside the ProcessHandler_OnCustomMessage
- salvadordf
- Posts: 4620
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: How to Get Js Result outside the ProcessHandler_OnCustomMessage
The page goes blank because the process crashes.
I've modified the FastDomVisitor code to send a message back to the browser process with customized parameters.
I'll upload it as soon as I fix the drag and drop problem in OSR mode.
I've modified the FastDomVisitor code to send a message back to the browser process with customized parameters.
I'll upload it as soon as I fix the drag and drop problem in OSR mode.
- salvadordf
- Posts: 4620
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: How to Get Js Result outside the ProcessHandler_OnCustomMessage
I forgot to add that the FastDomVisitor modification would enable you to get any result back to your main form when you visit the DOM.
In order to get JS results you would only have to modify the uTestExtension.pas file. Add a new class procedure that simply sends a text variable to the browser process. Something like this :
In your JS code you would call "myextension.sendresulttobrowser" the same way you call the "myextension.mouseover" function declared in uTestExtension.
You will also need to modify the Chromium1ProcessMessageReceived procedure to recognize the msgname parameter the same way it recognizes the "mouseover" message name.
I'll upload all the modifications as soon as I can.
In order to get JS results you would only have to modify the uTestExtension.pas file. Add a new class procedure that simply sends a text variable to the browser process. Something like this :
Code: Select all
class procedure TTestExtension.sendresulttobrowser(const msgtext, msgname : string);
var
msg: ICefProcessMessage;
begin
msg := TCefProcessMessageRef.New(msgname); // customized message name
msg.ArgumentList.SetString(0, msgtext);
TCefv8ContextRef.Current.Browser.SendProcessMessage(PID_BROWSER, msg);
end;
You will also need to modify the Chromium1ProcessMessageReceived procedure to recognize the msgname parameter the same way it recognizes the "mouseover" message name.
I'll upload all the modifications as soon as I can.
- salvadordf
- Posts: 4620
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: How to Get Js Result outside the ProcessHandler_OnCustomMessage
Download the latest version of CEF4Delphi, build the MiniBrowser, right-click on a web page and select "Visit DOM in Javascript".
You'll see a new window with the HTML code inside the BODY element.
If you click on the "Visit DOM in CEF" you'll see the document title in the status bar.
You'll see a new window with the HTML code inside the BODY element.
If you click on the "Visit DOM in CEF" you'll see the document title in the status bar.
Re: How to Get Js Result outside the ProcessHandler_OnCustomMessage
Great Big News,Very Very Thank you.!