diff --git a/demos/Delphi_VCL/DOMVisitor/uDOMVisitor.pas b/demos/Delphi_VCL/DOMVisitor/uDOMVisitor.pas index eb162c29..8c147748 100644 --- a/demos/Delphi_VCL/DOMVisitor/uDOMVisitor.pas +++ b/demos/Delphi_VCL/DOMVisitor/uDOMVisitor.pas @@ -61,11 +61,14 @@ const MINIBROWSER_COPYFRAMEIDS_2 = WM_APP + $104; MINIBROWSER_SHOWMESSAGE = WM_APP + $105; MINIBROWSER_SHOWSTATUSTEXT = WM_APP + $106; + MINIBROWSER_VISITDOM_JS = WM_APP + $107; MINIBROWSER_CONTEXTMENU_VISITDOM_PARTIAL = MENU_ID_USER_FIRST + 1; MINIBROWSER_CONTEXTMENU_VISITDOM_FULL = MENU_ID_USER_FIRST + 2; MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS_1 = MENU_ID_USER_FIRST + 3; MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS_2 = MENU_ID_USER_FIRST + 4; + MINIBROWSER_CONTEXTMENU_VISITDOM_JS = MENU_ID_USER_FIRST + 5; + MINIBROWSER_CONTEXTMENU_SETINPUTVALUE_JS = MENU_ID_USER_FIRST + 6; DOMVISITOR_MSGNAME_PARTIAL = 'domvisitorpartial'; DOMVISITOR_MSGNAME_FULL = 'domvisitorfull'; @@ -74,6 +77,8 @@ const FRAMEIDS_MSGNAME = 'getframeids'; CONSOLE_MSG_PREAMBLE = 'DOMVISITOR'; + NODE_ID = 'keywords'; + type TDOMVisitorFrm = class(TForm) CEFWindowParent1: TCEFWindowParent; @@ -124,6 +129,7 @@ type procedure BrowserDestroyMsg(var aMessage : TMessage); message CEF_DESTROY; procedure VisitDOMMsg(var aMessage : TMessage); message MINIBROWSER_VISITDOM_PARTIAL; 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 CopyFrameIDs2(var aMessage : TMessage); message MINIBROWSER_COPYFRAMEIDS_2; procedure ShowMessageMsg(var aMessage : TMessage); message MINIBROWSER_SHOWMESSAGE; @@ -224,8 +230,6 @@ begin end; procedure SimpleNodeSearch(const aDocument: ICefDomDocument; const aFrame : ICefFrame); -const - NODE_ID = 'keywords'; // ID of the search box node found in the forum var TempNode : ICefDomNode; TempJSCode, TempMessage : string; @@ -242,7 +246,15 @@ begin // 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 := '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 + '");'; aFrame.ExecuteJavaScript(TempJSCode, 'about:blank', 0); end; @@ -431,8 +443,10 @@ procedure TDOMVisitorFrm.Chromium1BeforeContextMenu(Sender: TObject; begin 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_JS, 'Visit DOM using JavaScript'); 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_SETINPUTVALUE_JS, 'Set INPUT value using JavaScript'); end; procedure TDOMVisitorFrm.Chromium1BeforePopup(Sender: TObject; @@ -491,11 +505,17 @@ begin MINIBROWSER_CONTEXTMENU_VISITDOM_FULL : PostMessage(Handle, MINIBROWSER_VISITDOM_FULL, 0, 0); + MINIBROWSER_CONTEXTMENU_VISITDOM_JS : + PostMessage(Handle, MINIBROWSER_VISITDOM_JS, 0, 0); + MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS_1 : PostMessage(Handle, MINIBROWSER_COPYFRAMEIDS_1, 0, 0); MINIBROWSER_CONTEXTMENU_COPYFRAMEIDS_2 : PostMessage(Handle, MINIBROWSER_COPYFRAMEIDS_2, 0, 0); + + MINIBROWSER_CONTEXTMENU_SETINPUTVALUE_JS : + frame.ExecuteJavaScript('document.getElementById("keywords").value = "qwerty";', 'about:blank', 0); end; end; @@ -606,6 +626,19 @@ begin Chromium1.SendProcessMessage(PID_RENDERER, TempMsg); 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); var i : NativeUInt; diff --git a/source/uCEFOLEDragAndDrop.pas b/source/uCEFOLEDragAndDrop.pas index 0828a42b..a2a035b8 100644 --- a/source/uCEFOLEDragAndDrop.pas +++ b/source/uCEFOLEDragAndDrop.pas @@ -10,7 +10,7 @@ // For more information about CEF4Delphi visit : // https://www.briskbard.com/index.php?lang=en&pageid=cef // -// Copyright © 2020 Salvador Diaz Fau. All rights reserved. +// Copyright © 2020 Salvador Diaz Fau. All rights reserved. // // ************************************************************************ // ************ vvvv Original license and comments below vvvv ************* diff --git a/update_CEF4Delphi.json b/update_CEF4Delphi.json index 958dc590..82406cb4 100644 --- a/update_CEF4Delphi.json +++ b/update_CEF4Delphi.json @@ -2,7 +2,7 @@ "UpdateLazPackages" : [ { "ForceNotify" : true, - "InternalVersion" : 150, + "InternalVersion" : 152, "Name" : "cef4delphi_lazarus.lpk", "Version" : "83.4.0.0" }