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 get HTML code from TChromiumWindow

Post Reply
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to get HTML code from TChromiumWindow

Post by salvadordf »

Create a procedure to handle the OnTextResultAvailable event and assign it to TChromiumWindow.ChromiumBrowser.OnTextResultAvailable.
Then call TChromiumWindow.ChromiumBrowser.RetrieveHTML and you will receive the HTML in the procedure you created previously.

TChromiumWindow was created to add very simple browsers to apps.
If you need to use some functions or events it's much easier to use the TChromium and TCEFWindowParent components.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to get HTML code from TChromiumWindow

Post by salvadordf »

Askerman wrote: Fri Mar 23, 2018 8:23 pm I have error [dcc32 Error] Main.pas(129): E2009 Incompatible types: 'Parameter lists differ' on line "ChromiumWindow1.ChromiumBrowser.OnTextResultAvailable := GetHtml;". What i should to do?

My code :

Code: Select all

...
type
  TForm1 = class (TForm)
    ChromiumWindow1 : TChromiumWindow;
    procedure FormCreate (Sender : TObject);
  private
    {Private declarations}
  public
    procedure GetHtml (Sender : TObject; aText : String);
  end;
 ...
 procedure TForm1.FormCreate (Sender : TObject);
    begin
      ChromiumWindow1.CreateBrowser;
      ChromiumWindow1.ChromiumBrowser.OnTextResultAvailable := GetHtml;
    end;
 
 procedure TForm1.GetHtml (Sender : TObject; aText : String);
   begin
      //My code;
   end;
...
The MiniBrowser demo has all the code to copy the HTML code in the clipboard.
Declare the GetHTML like this :

Code: Select all

procedure GetHtml(Sender: TObject; const aText: string);
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to get HTML code from TChromiumWindow

Post by salvadordf »

beryindo wrote: Sat Mar 24, 2018 1:43 am RetrieveHTML is it equal to view page source ?
I am try this code for CEFWindowsparent and TChromium. But not work

Code: Select all

procedure TForm1.Chromium1TextResultAvailable(Sender: TObject;
  const aText: string);
begin
  Chromium1.RetrieveHTML(aText);
  MemoRespon.Text := aText;
end;
The MiniBrowser demo has all the code to copy the HTML code in the clipboard.
You have to call RetrieveHTML outside the Chromium1TextResultAvailable procedure.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to get HTML code from TChromiumWindow

Post by salvadordf »

Hi,

To get the HTML you need to follow these steps :
  • Imlement the TChromium.OnTextResultAvailable event because the HTML will be received in the 'aText parameter from this is event.
  • Call TChromium.RetrieveHTML when the document is loaded.
  • After a few milliseconds the TChromium.OnTextResultAvailable event is triggered and you can copy the aText parameter with the HTML.
The MiniBrowser demo has the code for all these steps in the CopyHTMLMsg and Chromium1TextResultAvailable procedures.
It saves the aText parameter in the clipboard but you can save it wherever you need.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to get HTML code from TChromiumWindow

Post by salvadordf »

Visit this page :
https://github.com/salvadordf/CEF4Delph ... rowser.pas

Scroll to the line 934 for the CopyHTMLMsg code and line 752 for the Chromium1TextResultAvailable code.
Post Reply