mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-01-03 10:15:38 +02:00
Added a new option to visit the DOM using JavaScript in DOMVisitor demo
- Removed the calls to ICefDomNode.GetValue and ICefDomNode.SetValue in DOMVisitor demo due to a CEF issue. - Added more code comments to the DOMVisitor demo.
This commit is contained in:
parent
b19620c618
commit
ae83f0e54c
@ -61,11 +61,13 @@ const
|
|||||||
MINIBROWSER_COPYFRAMEIDS_2 = WM_APP + $104;
|
MINIBROWSER_COPYFRAMEIDS_2 = WM_APP + $104;
|
||||||
MINIBROWSER_SHOWMESSAGE = WM_APP + $105;
|
MINIBROWSER_SHOWMESSAGE = WM_APP + $105;
|
||||||
MINIBROWSER_SHOWSTATUSTEXT = WM_APP + $106;
|
MINIBROWSER_SHOWSTATUSTEXT = WM_APP + $106;
|
||||||
|
MINIBROWSER_VISITDOM_JS = WM_APP + $107;
|
||||||
|
|
||||||
MINIBROWSER_CONTEXTMENU_VISITDOM_PARTIAL = MENU_ID_USER_FIRST + 1;
|
MINIBROWSER_CONTEXTMENU_VISITDOM_PARTIAL = MENU_ID_USER_FIRST + 1;
|
||||||
MINIBROWSER_CONTEXTMENU_VISITDOM_FULL = MENU_ID_USER_FIRST + 2;
|
MINIBROWSER_CONTEXTMENU_VISITDOM_FULL = MENU_ID_USER_FIRST + 2;
|
||||||
MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS_1 = MENU_ID_USER_FIRST + 3;
|
MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS_1 = MENU_ID_USER_FIRST + 3;
|
||||||
MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS_2 = MENU_ID_USER_FIRST + 4;
|
MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS_2 = MENU_ID_USER_FIRST + 4;
|
||||||
|
MINIBROWSER_CONTEXTMENU_VISITDOM_JS = MENU_ID_USER_FIRST + 5;
|
||||||
|
|
||||||
DOMVISITOR_MSGNAME_PARTIAL = 'domvisitorpartial';
|
DOMVISITOR_MSGNAME_PARTIAL = 'domvisitorpartial';
|
||||||
DOMVISITOR_MSGNAME_FULL = 'domvisitorfull';
|
DOMVISITOR_MSGNAME_FULL = 'domvisitorfull';
|
||||||
@ -74,6 +76,8 @@ const
|
|||||||
FRAMEIDS_MSGNAME = 'getframeids';
|
FRAMEIDS_MSGNAME = 'getframeids';
|
||||||
CONSOLE_MSG_PREAMBLE = 'DOMVISITOR';
|
CONSOLE_MSG_PREAMBLE = 'DOMVISITOR';
|
||||||
|
|
||||||
|
NODE_ID = 'keywords';
|
||||||
|
|
||||||
type
|
type
|
||||||
TDOMVisitorFrm = class(TForm)
|
TDOMVisitorFrm = class(TForm)
|
||||||
CEFWindowParent1: TCEFWindowParent;
|
CEFWindowParent1: TCEFWindowParent;
|
||||||
@ -124,6 +128,7 @@ type
|
|||||||
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
|
procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY;
|
||||||
procedure VisitDOMMsg(var aMessage : TMessage); message MINIBROWSER_VISITDOM_PARTIAL;
|
procedure VisitDOMMsg(var aMessage : TMessage); message MINIBROWSER_VISITDOM_PARTIAL;
|
||||||
procedure VisitDOM2Msg(var aMessage : TMessage); message MINIBROWSER_VISITDOM_FULL;
|
procedure VisitDOM2Msg(var aMessage : TMessage); message MINIBROWSER_VISITDOM_FULL;
|
||||||
|
procedure VisitDOM3Msg(var aMessage : TMessage); message MINIBROWSER_VISITDOM_JS;
|
||||||
procedure CopyFrameIDs1(var aMessage : TMessage); message MINIBROWSER_COPYFRAMEIDS_1;
|
procedure CopyFrameIDs1(var aMessage : TMessage); message MINIBROWSER_COPYFRAMEIDS_1;
|
||||||
procedure CopyFrameIDs2(var aMessage : TMessage); message MINIBROWSER_COPYFRAMEIDS_2;
|
procedure CopyFrameIDs2(var aMessage : TMessage); message MINIBROWSER_COPYFRAMEIDS_2;
|
||||||
procedure ShowMessageMsg(var aMessage : TMessage); message MINIBROWSER_SHOWMESSAGE;
|
procedure ShowMessageMsg(var aMessage : TMessage); message MINIBROWSER_SHOWMESSAGE;
|
||||||
@ -224,11 +229,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure SimpleNodeSearch(const aDocument: ICefDomDocument; const aFrame : ICefFrame);
|
procedure SimpleNodeSearch(const aDocument: ICefDomDocument; const aFrame : ICefFrame);
|
||||||
const
|
|
||||||
NODE_ID = 'keywords'; // ID of the search box node found in the forum
|
|
||||||
var
|
var
|
||||||
TempNode : ICefDomNode;
|
TempNode : ICefDomNode;
|
||||||
TempJSCode, TempMessage : string;
|
TempJSCode, TempMessage, TempName : string;
|
||||||
begin
|
begin
|
||||||
try
|
try
|
||||||
if (aDocument <> nil) then
|
if (aDocument <> nil) then
|
||||||
@ -242,7 +245,15 @@ begin
|
|||||||
// execute "console.log" in JavaScript to send TempMessage with a
|
// execute "console.log" in JavaScript to send TempMessage with a
|
||||||
// known preamble that will be used to identify the message in the
|
// known preamble that will be used to identify the message in the
|
||||||
// TChromium.OnConsoleMessage event.
|
// TChromium.OnConsoleMessage event.
|
||||||
TempMessage := 'name:' + quotedstr(TempNode.Name) + ' - value:' + quotedstr(TempNode.GetValue);
|
|
||||||
|
// CEF has some known issues with ICefDomNode.GetValue and ICefDomNode.SetValue
|
||||||
|
// Use JavaScript if you need to get or set the value of HTML elements.
|
||||||
|
// For example, if you want to use the "console trick" and you want
|
||||||
|
// to get the value of the search box in our forum you would have to
|
||||||
|
// execute this JavaScript code :
|
||||||
|
// console.log("DOMVISITOR" + document.getElementById("keywords").value);
|
||||||
|
|
||||||
|
TempMessage := 'name:' + quotedstr(TempNode.Name);
|
||||||
TempJSCode := 'console.log("' + CONSOLE_MSG_PREAMBLE + TempMessage + '");';
|
TempJSCode := 'console.log("' + CONSOLE_MSG_PREAMBLE + TempMessage + '");';
|
||||||
aFrame.ExecuteJavaScript(TempJSCode, 'about:blank', 0);
|
aFrame.ExecuteJavaScript(TempJSCode, 'about:blank', 0);
|
||||||
end;
|
end;
|
||||||
@ -431,6 +442,7 @@ procedure TDOMVisitorFrm.Chromium1BeforeContextMenu(Sender: TObject;
|
|||||||
begin
|
begin
|
||||||
model.AddItem(MINIBROWSER_CONTEXTMENU_VISITDOM_PARTIAL, 'Visit DOM in CEF (only Title)');
|
model.AddItem(MINIBROWSER_CONTEXTMENU_VISITDOM_PARTIAL, 'Visit DOM in CEF (only Title)');
|
||||||
model.AddItem(MINIBROWSER_CONTEXTMENU_VISITDOM_FULL, 'Visit DOM in CEF (BODY HTML)');
|
model.AddItem(MINIBROWSER_CONTEXTMENU_VISITDOM_FULL, 'Visit DOM in CEF (BODY HTML)');
|
||||||
|
model.AddItem(MINIBROWSER_CONTEXTMENU_VISITDOM_JS, 'Visit DOM using JavaScript');
|
||||||
model.AddItem(MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS_1, 'Copy frame IDs in the browser process');
|
model.AddItem(MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS_1, 'Copy frame IDs in the browser process');
|
||||||
model.AddItem(MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS_2, 'Copy frame IDs in the render process');
|
model.AddItem(MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS_2, 'Copy frame IDs in the render process');
|
||||||
end;
|
end;
|
||||||
@ -491,6 +503,9 @@ begin
|
|||||||
MINIBROWSER_CONTEXTMENU_VISITDOM_FULL :
|
MINIBROWSER_CONTEXTMENU_VISITDOM_FULL :
|
||||||
PostMessage(Handle, MINIBROWSER_VISITDOM_FULL, 0, 0);
|
PostMessage(Handle, MINIBROWSER_VISITDOM_FULL, 0, 0);
|
||||||
|
|
||||||
|
MINIBROWSER_CONTEXTMENU_VISITDOM_JS :
|
||||||
|
PostMessage(Handle, MINIBROWSER_VISITDOM_JS, 0, 0);
|
||||||
|
|
||||||
MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS_1 :
|
MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS_1 :
|
||||||
PostMessage(Handle, MINIBROWSER_COPYFRAMEIDS_1, 0, 0);
|
PostMessage(Handle, MINIBROWSER_COPYFRAMEIDS_1, 0, 0);
|
||||||
|
|
||||||
@ -606,6 +621,19 @@ begin
|
|||||||
Chromium1.SendProcessMessage(PID_RENDERER, TempMsg);
|
Chromium1.SendProcessMessage(PID_RENDERER, TempMsg);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TDOMVisitorFrm.VisitDOM3Msg(var aMessage : TMessage);
|
||||||
|
var
|
||||||
|
TempJSCode, TempMessage : string;
|
||||||
|
begin
|
||||||
|
// Here we send the name and value of the element with the "console trick".
|
||||||
|
// We execute "console.log" in JavaScript to send TempMessage with a
|
||||||
|
// known preamble that will be used to identify the message in the
|
||||||
|
// TChromium.OnConsoleMessage event.
|
||||||
|
TempMessage := 'document.getElementById("' + NODE_ID + '").value';
|
||||||
|
TempJSCode := 'console.log("' + CONSOLE_MSG_PREAMBLE + '" + ' + TempMessage + ');';
|
||||||
|
chromium1.ExecuteJavaScript(TempJSCode, 'about:blank');
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TDOMVisitorFrm.CopyFrameIDs1(var aMessage : TMessage);
|
procedure TDOMVisitorFrm.CopyFrameIDs1(var aMessage : TMessage);
|
||||||
var
|
var
|
||||||
i : NativeUInt;
|
i : NativeUInt;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"UpdateLazPackages" : [
|
"UpdateLazPackages" : [
|
||||||
{
|
{
|
||||||
"ForceNotify" : true,
|
"ForceNotify" : true,
|
||||||
"InternalVersion" : 150,
|
"InternalVersion" : 151,
|
||||||
"Name" : "cef4delphi_lazarus.lpk",
|
"Name" : "cef4delphi_lazarus.lpk",
|
||||||
"Version" : "83.4.0.0"
|
"Version" : "83.4.0.0"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user