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.

Execute "ExecuteJavaScript" before showing the page

Post Reply
X-Vlad
Posts: 1
Joined: Mon Nov 16, 2020 3:17 pm

Execute "ExecuteJavaScript" before showing the page

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

Re: Execute "ExecuteJavaScript" before showing the page

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