mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-05-23 21:50:21 +02:00
Copy the HTML usiing JS in DOMVIsitor
This commit is contained in:
parent
627ff6a532
commit
cf106b5363
@ -10,6 +10,7 @@ uses
|
|||||||
System.SyncObjs, System.Classes, Vcl.Graphics, Vcl.Menus, Vcl.Controls,
|
System.SyncObjs, System.Classes, Vcl.Graphics, Vcl.Menus, Vcl.Controls,
|
||||||
Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, System.Types,
|
Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, System.Types,
|
||||||
Vcl.ComCtrls, Vcl.ClipBrd, System.UITypes,
|
Vcl.ComCtrls, Vcl.ClipBrd, System.UITypes,
|
||||||
|
{$IFDEF DELPHI21_UP}System.NetEncoding,{$ELSE}Web.HTTPApp,{$ENDIF}
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Menus, SyncObjs,
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Menus, SyncObjs,
|
||||||
Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Types, ComCtrls, ClipBrd,
|
Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Types, ComCtrls, ClipBrd,
|
||||||
@ -493,27 +494,23 @@ end;
|
|||||||
procedure TDOMVisitorFrm.Chromium1ConsoleMessage(Sender: TObject;
|
procedure TDOMVisitorFrm.Chromium1ConsoleMessage(Sender: TObject;
|
||||||
const browser: ICefBrowser; level: TCefLogSeverity; const message, source: ustring;
|
const browser: ICefBrowser; level: TCefLogSeverity; const message, source: ustring;
|
||||||
line: Integer; out Result: Boolean);
|
line: Integer; out Result: Boolean);
|
||||||
|
var
|
||||||
|
TempResult : string;
|
||||||
begin
|
begin
|
||||||
// In this event we receive the message with the name and value of a DOM node
|
// In this event we receive the message with the HTML
|
||||||
// from the render process.
|
// from the render process.
|
||||||
// This event may receive many other messages but we identify our message
|
// This event may receive many other messages but we identify our message
|
||||||
// thanks to the preamble.
|
// thanks to the preamble.
|
||||||
// The we set MsgContents with the rest of the message and send a
|
|
||||||
// MINIBROWSER_SHOWMESSAGE message to show MsgContents in the main thread safely.
|
|
||||||
// This and many other TChromium events are executed in a CEF thread. The VCL
|
|
||||||
// should be used only in the main thread and we use a message and a field
|
|
||||||
// protected by a synchronization object to call showmessage safely.
|
|
||||||
if (length(message) > 0) and
|
if (length(message) > 0) and
|
||||||
(copy(message, 1, length(CONSOLE_MSG_PREAMBLE)) = CONSOLE_MSG_PREAMBLE) then
|
(copy(message, 1, length(CONSOLE_MSG_PREAMBLE)) = CONSOLE_MSG_PREAMBLE) then
|
||||||
begin
|
begin
|
||||||
MsgContents := copy(message, succ(length(CONSOLE_MSG_PREAMBLE)), length(message));
|
// Remove CONSOLE_MSG_PREAMBLE to get the encoded result
|
||||||
|
TempResult := copy(message, succ(length(CONSOLE_MSG_PREAMBLE)), length(message));
|
||||||
if (length(MsgContents) = 0) then
|
// Decode the result and copy to the clipboard.
|
||||||
MsgContents := 'There was an error reading the search box information'
|
Clipboard.AsText := TNetEncoding.URL.Decode(TempResult);
|
||||||
else
|
// Update the status bar text in the main application thread
|
||||||
MsgContents := 'Search box information: ' + quotedstr(MsgContents);
|
StatusText := 'HTML copied to the clipboard';
|
||||||
|
PostMessage(Handle, MINIBROWSER_SHOWSTATUSTEXT, 0, 0);
|
||||||
PostMessage(Handle, MINIBROWSER_SHOWMESSAGE, 0, 0);
|
|
||||||
|
|
||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
@ -783,11 +780,13 @@ procedure TDOMVisitorFrm.VisitDOM3Msg(var aMessage : TMessage);
|
|||||||
var
|
var
|
||||||
TempJSCode, TempMessage : string;
|
TempJSCode, TempMessage : string;
|
||||||
begin
|
begin
|
||||||
// Here we send the name and value of the element with the "console trick".
|
// Here we send the HTML with the "console trick".
|
||||||
|
|
||||||
|
// We need to encode the HTML with encodeURIComponent but it might be necessary to encode it with btoa (Base64)
|
||||||
|
TempMessage := 'encodeURIComponent(document.documentElement.outerHTML)';
|
||||||
// We execute "console.log" in JavaScript to send TempMessage with a
|
// We 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 := 'document.getElementById("' + NODE_ID + '").value';
|
|
||||||
TempJSCode := 'console.log("' + CONSOLE_MSG_PREAMBLE + '" + ' + TempMessage + ');';
|
TempJSCode := 'console.log("' + CONSOLE_MSG_PREAMBLE + '" + ' + TempMessage + ');';
|
||||||
chromium1.ExecuteJavaScript(TempJSCode, 'about:blank');
|
chromium1.ExecuteJavaScript(TempJSCode, 'about:blank');
|
||||||
end;
|
end;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"UpdateLazPackages" : [
|
"UpdateLazPackages" : [
|
||||||
{
|
{
|
||||||
"ForceNotify" : true,
|
"ForceNotify" : true,
|
||||||
"InternalVersion" : 669,
|
"InternalVersion" : 670,
|
||||||
"Name" : "cef4delphi_lazarus.lpk",
|
"Name" : "cef4delphi_lazarus.lpk",
|
||||||
"Version" : "130.1.9"
|
"Version" : "130.1.9"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user