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 use different fields in the ICefDomDocument interface

Post Reply
Pcrepair
Posts: 10
Joined: Tue Sep 27, 2022 5:09 pm

How to use different fields in the ICefDomDocument interface

Post by Pcrepair »

Good afternoon salvadordf.

There is a procedure DOMVisitor_OnDocAvailable(const browser: ICefBrowser;
const frame: ICefFrame; const document: ICefDomDocument); in uDOMVisitor.pas

When called, you can get for example: "document.Title" or "document.BaseUrl" or "document.Head.ElementInnerText" and output via

Code: Select all

TempMessage.ArgumentList.SetString(0, document.Head.ElementInnerText); 
some data from DOM further into the application.

But this requires rewriting and recompiling the program every time.

It's clear that "document.Title" is a field and you can't just substitute "Title" or "BaseUrl" or "ElementInnerText", but if:

Code: Select all

 if gDocType = 0 then
      TempMessage.ArgumentList.SetString(0, document.Title);

    If gDocType = 1 then
      TempMessage.ArgumentList.SetString(0, document.BaseUrl);


    If gDocType = 2 then
      TempMessage.ArgumentList.SetString(0, document.Head.ElementInnerText); 
Where gDocType is a global variable accessible from the main form

Code: Select all

procedure TMain.Button2Click(Sender: TObject);
begin (* get DOM *)
  gDocType:=SpinEdit1.Value;
  crm.SendProcessMessage(PID_RENDER,
    TCefProcessMessageRef.New(RETRIEVEDOM_MSGNAME_PARTIAL));
end;
still only passes

Code: Select all

 if gDocType = 0 then
      TempMessage.ArgumentList.SetString(0, document.Title);
so it turns out that I can't pass gDocType to DOMVisitor_OnDocAvailable, but then how do I manage the field selection in the document promptly

If it is possible, please point out the way

Thank you.
User avatar
salvadordf
Posts: 4083
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to use different fields in the ICefDomDocument interface

Post by salvadordf »

Chromium uses a different process to render a web page.
This means that the local variables in the main process are not visible in the renderer process.

gDocType is defined in the main browser process and GlobalCEFApp.OnProcessMessageReceived is executed in the renderer process.

You need to pass the gDocType value in the argument list of the process message sent from the main process to the renderer process.

Read this for more information :
https://github.com/salvadordf/CEF4Delphi/blob/25452fba097802853b8df59e9f6af74cac4ac735/demos/Delphi_VCL/JavaScript/JSExtension/uJSExtension.pas#L122
Post Reply