Page 1 of 1

Re: How to get HTML code from TChromiumWindow

Posted: Fri Mar 23, 2018 6:26 pm
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.

Re: How to get HTML code from TChromiumWindow

Posted: Sat Mar 24, 2018 10:00 am
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);

Re: How to get HTML code from TChromiumWindow

Posted: Sat Mar 24, 2018 10:01 am
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.

Re: How to get HTML code from TChromiumWindow

Posted: Mon Apr 09, 2018 6:42 am
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.

Re: How to get HTML code from TChromiumWindow

Posted: Tue Apr 10, 2018 2:58 pm
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.