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.

Problem Registering a JavaScript Extension

Post Reply
User avatar
salvadordf
Posts: 4067
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Problem Registering a JavaScript Extension

Post by salvadordf »

Please, download CEF4Delphi again from GitHub.

The JS extension demos have more debug information now. JSExtension and JSRTTIExtension will create a "debug.log" file where they add custom messages with CefDebugLog calls as you can see in the GlobalCEFApp_OnWebKitInitialized procedure.

CefDebugLog also adds the process ID (PID) to the debug.log file to debug the renderer process with the "Run->Run Without Debugging..." option in Delphi as described here :
https://www.briskbard.com/index.php?lan ... #debugging

Check the log file to see if the extension was registered successfully.

The extension should be registered all the time but in some rare cases it's "undefined" :
https://magpcss.org/ceforum/viewtopic.p ... 69&p=40484

PS : I removed the mutation observer from the JSRTTIExtension demo because of this :
https://stackoverflow.com/questions/323 ... -input-tag
User avatar
salvadordf
Posts: 4067
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Problem Registering a JavaScript Extension

Post by salvadordf »

Please, check that the code for CEFSubProcess assigns the GlobalCEFApp.OnWebKitInitialized event before the GlobalCEFApp.StartSubProcess call :

Code: Select all

GlobalCEFApp.OnWebKitInitialized := GlobalCEFApp_OnWebKitInitialized;
If you copied the conditional directives you need to build CEFSubProcess in "debug" mode in Delphi to enable the code that adds log entries.
User avatar
salvadordf
Posts: 4067
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Problem Registering a JavaScript Extension

Post by salvadordf »

Move the GlobalCEFApp_OnWebKitInitialized procedure to the CEFSubProcess DPR file.
Assign GlobalCEFApp_OnWebKitInitialized to the GlobalCEFApp event before the GlobalCEFApp.StartSubProcess call like this :

Code: Select all

GlobalCEFApp.OnWebKitInitialized := GlobalCEFApp_OnWebKitInitialized;
The GlobalCEFApp.OnWebKitInitialized event is triggered in the render process, which is one of the subprocesses.

GlobalCEFApp.DeleteCache and GlobalCEFApp.DeleteCookies should only be used in the main process and only if you need to delete the cache and cookies before CEF is initialized.
User avatar
salvadordf
Posts: 4067
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Problem Registering a JavaScript Extension

Post by salvadordf »

stwizard wrote: Tue Oct 01, 2019 8:49 pmJust to be clear. You want me to remove the GlobalCEFApp_OnWebKitInitialized in my main app and it should be only in the CEFSubProcess. Is that correct?
Yes, that's correct.

GlobalCEFApp_OnWebKitInitialized only works in CEFSubProcess because it's executed in the render process.

If you were using the same EXE for all processes then you would put everything in the same place but if you use CEFSubProcess then you need to put some events in the right DPR.

GlobalCEFApp has several events corresponding to the methods defined in ICefBrowserProcessHandler, ICefRenderProcessHandler, ICefRegisterCDMCallback, ICefLoadHandler and ICefResourceBundleHandler.

As you can see in the documentation, the methods for ICefRenderProcessHandler are executed in the render process :
https://magpcss.org/ceforum/apidocs3/pr ... ndler.html

One of the ICefRenderProcessHandler methods is OnWebKitInitialized
Post Reply