Page 1 of 1

Execute "ExecuteJavaScript" before showing the page

Posted: Mon Nov 16, 2020 3:20 pm
by X-Vlad
Hello, how to execute "ExecuteJavaScript" before showing the page, an example of how it works as an ad blocker, it hides blocks and then we see the page.

Re: Execute "ExecuteJavaScript" before showing the page

Posted: Mon Nov 16, 2020 3:51 pm
by salvadordf
Hi,

If you try to call ExecuteJavascript before the TChromium initialization it won't work.

Ad blockers are usually a browser extension and right now there is limited support for them in CEF. You have a couple of demos in the /demos/Delphi_VCL/Extensions directory.

However, there are alternative ways to have an ad blocker like using the TChromium.OnBeforeResourceLoad event to block some resources depending on your criteria.

Read this document about the JavaScript integration in CEF :
https://bitbucket.org/chromiumembedded/ ... gration.md

The demos in the /demos/Delphi_VCL/JavaScript directory are Delphi translations of all the examples in that document.

Read the code comments in the demos, especially the comments in the JSExtension demo here :
https://github.com/salvadordf/CEF4Delph ... n.pas#L122