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.

HTML Document

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

Re: HTML Document

Post by salvadordf »

Read this thread :
https://www.briskbard.com/forum/viewtop ... &t=30&p=74

If you get the HTML before the document is fully loaded then you risk having an incomplete result.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: HTML Document

Post by salvadordf »

Please post the user agent string you're using to replicate the issue.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: HTML Document

Post by salvadordf »

I added this code to the MiniBrowser demo before the GlobalCEFApp.StartMainProcess call :

Code: Select all

  GlobalCEFApp.UserAgent := 'Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; Microsoft; Lumia 640 LTE) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537)';
Then I run the MiniBrowser and the mobile version of Google is loaded. After that I right-clicked and selected the "Copy HTML to clipboard" option in the context menu.

It worked correctly, the HTML source was copied to the clipboard and the demo didn't freeze.

Please, check that your app calls TChromium.RetrieveHTML and uses the TChromium.OnTextResultAvailable event like MiniBrowser.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: HTML Document

Post by salvadordf »

Ideally, you should wait until the main frame is fully loaded before attempting to get the HTML code.

Read these forum threads to know more details :
https://www.briskbard.com/forum/viewtopic.php?f=8&t=261
https://www.briskbard.com/forum/viewtopic.php?f=8&t=333
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: HTML Document

Post by salvadordf »

The easiest way would be this :
  • Use the TChromium.OnLoadingStateChange event and check if isLoading is FALSE before calling TChromium.RetrieveHTML.
  • Use the TChromium.OnTextResultAvailable event to receive the HTML in the aText parameter.
If you call TChromium.RetrieveHTML without parameters you will only receive the HTML from the main frame.
If the web page has several frames you will need to read this forum thread :
https://www.briskbard.com/forum/viewtop ... 449&p=1949

If you call TChromium.RetrieveHTML while the page is still loading you may get partial results at best.

Remember that the MiniBrowser demo has all the code to get the HTML code.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: HTML Document

Post by salvadordf »

Then use the ResponseFilterBrowser demo.

It's a much more complicated demo where you can intercept or filter raw resource contents while they are being downloaded but I'm not sure if it works with resources downloaded using JavaScript.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: HTML Document

Post by salvadordf »

Nekich wrote: Sun Jun 10, 2018 4:30 pm it's difficult, can try to get it somehow through ResourceLoadComplete?
And is it possible to pull out the html from browser, frame, request, response?
You would need to call Frame.GetSource with a ICefStringVisitor parameter but that's exactly what TChromium.RetrieveHTML does.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: HTML Document

Post by salvadordf »

I don't know. I guess there's a technical reason in Chromium why you have to use a visitor.

The CEF3 API defines what CEF4Delphi calls ICefRequestHandler.OnResourceLoadComplete with those parameters :
https://bitbucket.org/chromiumembedded/ ... capi.h-222
Post Reply