Page 1 of 1

Load page source code

Posted: Mon Oct 25, 2021 7:28 pm
by Uefi1
Can i load the source code of the page to execute javascript in it ???

Re: Load page source code

Posted: Tue Oct 26, 2021 9:32 am
by salvadordf
Hi,

Yes, you can do all that. See the code behind the upper-right button in the MiniBrowser demo to see how to load files with a FILE URI or a DATA URI.

That demo also shows how to execute JavaScript code with TChromium.ExecuteJavaScript

Chromium has some security limitations with the FILE URIs that can be avoided by registering a custom scheme. See the SchemeRegistrationBrowser demo and register HTTP in case you have that problem.

Re: Load page source code

Posted: Tue Oct 26, 2021 5:36 pm
by Uefi1
My main problem is that you need to execute javascript in a multi-threaded application, but dcef4 asynchronous can not tell how to do it?

Re: Load page source code

Posted: Wed Oct 27, 2021 8:46 am
by salvadordf
There's only one way to execute JavaScript code that I mentioned before.
If the application has multiple threads you can call TChromium.ExecuteJavaScript from any thread.

Search "ExecuteJavaScript" in all the demos and you will find many examples.

Re: Load page source code

Posted: Thu Oct 28, 2021 3:11 am
by Uefi1
i know how to execute javascript i don't know how to sync with chrome, i need to
1. go to the site
2. execute javascript
3. get source code page
4. destroy/Terminated Chromium
And do it all multithreaded
Chromium is asynchronous so I don't know how to wait fulfillment

Re: Load page source code

Posted: Thu Oct 28, 2021 7:39 am
by salvadordf
Try using some custom "state" field to keep track of the current step the app is executing. For example, state could have this type :

Code: Select all

TMyCustomState = (csIdle, csLoading, csExecutingJS, csGettingCode, csDestroying);

Re: Load page source code

Posted: Thu Oct 28, 2021 4:41 pm
by Uefi1
Can you post the source code for this?

Re: Load page source code

Posted: Fri Oct 29, 2021 7:10 am
by salvadordf
You'll find most of the code you need to implement those functions with CEF4Delphi in the demos but there are no demo with exactly the same features you ask for.

You will have to implement that state controlled program for yourself.