How to Get Js Result outside the ProcessHandler_OnCustomMessage
Posted: Thu Jul 13, 2017 4:50 am
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() "
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() "