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.

getting html source immediately

Post Reply
snoop
Posts: 75
Joined: Mon Jul 10, 2017 12:06 pm

getting html source immediately

Post by snoop »

hello!
I was using old dcef, and used easy way to get source like
s:=Chromium.Browser.MainFrame.Source;

IN new versions we have GetSource, GetSourceProc, also RetrieveHTML here, but I dont fully understand them...

I need single and easy-to-use procedure to get it, I used it with synchronize

procedure GetSource;
s:=Chromium.Browser.MainFrame.Source; //to variable
end;

...
synchronize(GetSource);

and in new version how can I do the same? Please help and write me this proc
User avatar
salvadordf
Posts: 4052
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: getting html source immediately

Post by salvadordf »

Hi,

Follow these steps :
  • Wait for the document to be fully loaded by checking frame.IsMain in the TChromium.OnLoadEnd event.
  • Call TChromium.RetrieveHTML.
  • Get the HTML source in the TChromium.OnTextResultAvailable event.
CEF3 now has multiple processes and threads. This is the easiest way to get the HTML source but it's not immediate.
snoop
Posts: 75
Joined: Mon Jul 10, 2017 12:06 pm

Re: getting html source immediately

Post by snoop »

hey thanks for fast response
I saw this in minibrowser demo but still don't get it fully
The thing is I need to know a source of pages often and fast, but Im afraid if this method will be a bit slow...it needs to be "close to immediate", because I have multithread project and as I've said Im using synchronize of that method so it takes a bit of time too

also, Im still deciding if I need to update from old DCEF3, does CEF4 really faster, more secure, more compatible like real browser,etc
User avatar
salvadordf
Posts: 4052
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: getting html source immediately

Post by salvadordf »

Depending on the web pages you want to visit to get the HTML source you could use much simpler and faster methods.
You could use TIdHTTP from the Indy components or use the WinInet functions.

If you still want to use CEF4Delphi you could use messages and critical sections instead of syncronize.
Once the webpage is fully loaded, the "RetreiveHTML" method is very fast.
snoop
Posts: 75
Joined: Mon Jul 10, 2017 12:06 pm

Re: getting html source immediately

Post by snoop »

application is interactive, the user needs to see a site and work on it, and some things must be changed from code (like clicking buttons on site, filling values). also, sometimes html source is needed during loading page or during executing script on site... So I still cant use new method of getting source properly... what a headache.. it was so easy and nice before! What I need to call after RetrieveHTML?

function GetSource: string;
begin
Chromium1.RetrieveHtml;
result:= ... ?
end;

Please help!
User avatar
salvadordf
Posts: 4052
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: getting html source immediately

Post by salvadordf »

Hi,

After calling RetreiveHTML you will receive the HTML source in the "aText" parameter from the TChromium.OnTextResultAvailable event.

RetreiveHTML will be on a different procedure than OnTextResultAvailable, so you can't use "syncronize".

In case you were using syncronize from a thread to call the TChromium function to get the HTML source, you will have to replace all that with messages between the thread and the form where TChromium is.
  • From the thread, send a customized message to the form to ask for the source code.
  • The form receives the message and calls RetreiveHTML.
  • A few milliseconds later the TChromium.OnTextResultAvailable event is triggered and you store the "aText" parameter in a variable that must be protected by a critical section.
  • Then you send another customized message to the thread to let it know that the result is ready.
  • The thread receives the "ready" message and reads the HTML source code stored in the form.
Post Reply