Page 1 of 1

RetrieveHTML Proc Is there a mistake?

Posted: Sun Jan 17, 2021 1:11 am
by asparagas
The text I got from the RetrieveHTML procedure and the text image I got from context menu command vievpagesource is different! What is the reason for this? When I run the RetrieveHTML procedure 2 times I get the correct result!

Re: RetrieveHTML Proc Is there a mistake?

Posted: Sun Jan 17, 2021 10:37 am
by salvadordf
TChromium.RetrieveHTML gets the HTML source from one frame. If we call it without parameters then it gets the HTML from the main frame only.

The "View page source" option in the context menu is not part of CEF. It's a Chromium function and I don't know how it's implemented.

If the web page changes the HTML source dinamically then TChromium.RetrieveHTML will return different results each time.

However, there could be an unexpected issue with this procedure too. Please, provide a step-by-step guide to reproduce this issue and I'll investigate.

Re: RetrieveHTML Proc Is there a mistake?

Posted: Sun Jan 17, 2021 1:31 pm
by asparagas
Thank you for your interest.

I tried all kinds of

yes, the web page is dynamically changing the content. I wait for 5 minutes, for example, I get the old result with retrievehtml again, I get it with viewpagesource, it always gives the correct result without waiting !! Interesting..

Re: RetrieveHTML Proc Is there a mistake?

Posted: Wed Jan 20, 2021 4:42 pm
by asparagas
I can't get the information I see on the screen from source code with retrievehtml !!

Re: RetrieveHTML Proc Is there a mistake?

Posted: Thu Jan 21, 2021 9:19 am
by salvadordf
Try getting the HTML using JavaScript instead.

Re: RetrieveHTML Proc Is there a mistake?

Posted: Fri Jan 22, 2021 7:23 pm
by asparagas
How is it going to be?

Can you sample if I request it very much?

I do not have that much information because ..

Re: RetrieveHTML Proc Is there a mistake?

Posted: Fri Jan 22, 2021 9:39 pm
by asparagas
tried the following ways and got results, is there any more logical way?

-.-.-.-.-.-

solution - 1:

type
TUYAPTransferFrm = class(TForm)
private
_asBrowser_Text_ :string;
end;

procedure TUYAPTransferFrm.StringVisitor(const str: ustring);
begin
_asBrowser_Text_ := str;
end;

procedure TUYAPTransferFrm.Button5Click(Sender: TObject);
var _CefStringVisitor_ :ICefStringVisitor;
begin
_CefStringVisitor_ := TCefFastStringVisitor.Create(StringVisitor);
Chromium1.Browser.MainFrame.GetSource ( _CefStringVisitor_ );
end;

-.-.-.-.-

solution - 2:

PostMessage(Handle, MINIBROWSER_COPYHTML, 0, 0);

Re: RetrieveHTML Proc Is there a mistake?

Posted: Sat Jan 23, 2021 9:32 am
by salvadordf
The code you posted with a string visitor is almost identical to the code behind the TChromium.RetrieveHTML function.

There are other ways but they have similar complexity :
  • JSExtension uses "innerHTML" in JavaScript and sends the results using a JavaScript extension : https://github.com/salvadordf/CEF4Delphi/blob/47fb09e887ced6803c59d2f573eca632b888ffa0/demos/Delphi_VCL/JavaScript/JSExtension/uJSExtension.pas#L391
  • The DevTools protocols has a method to get the HTML but it requires several steps to get the node IDs. I haven't tried this :
    https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getOuterHTML

Re: RetrieveHTML Proc Is there a mistake?

Posted: Sat Jan 23, 2021 11:49 am
by asparagas
thank you so much. I found the different solution in the "JavaScript \ JSEval" example .. best regards