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.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

Load page source code

Post Reply
User avatar
Uefi1
Posts: 43
Joined: Tue Aug 24, 2021 1:58 pm

Load page source code

Post by Uefi1 »

Can i load the source code of the page to execute javascript in it ???
User avatar
salvadordf
Posts: 4580
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Load page source code

Post 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.
User avatar
Uefi1
Posts: 43
Joined: Tue Aug 24, 2021 1:58 pm

Re: Load page source code

Post 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?
User avatar
salvadordf
Posts: 4580
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Load page source code

Post 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.
User avatar
Uefi1
Posts: 43
Joined: Tue Aug 24, 2021 1:58 pm

Re: Load page source code

Post 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
User avatar
salvadordf
Posts: 4580
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Load page source code

Post 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);
User avatar
Uefi1
Posts: 43
Joined: Tue Aug 24, 2021 1:58 pm

Re: Load page source code

Post by Uefi1 »

Can you post the source code for this?
User avatar
salvadordf
Posts: 4580
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Load page source code

Post 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.
Post Reply