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.

Retrun JS result Tchromium

subin
Posts: 20
Joined: Thu Sep 05, 2024 5:15 am

Re: Retrun JS result Tchromium

Post by subin »

Thanks a lot for your reply.

Please let me know when the event OnWebKitInitialized is triggered.

Thanks
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Retrun JS result Tchromium

Post by salvadordf »

As you can see in the documentation, that event is executed in the render process.

Read this to know how to debug code in multiple processes :
https://www.briskbard.com/index.php?lang=en&pageid=cef#debugging
subin
Posts: 20
Joined: Thu Sep 05, 2024 5:15 am

Re: Retrun JS result Tchromium

Post by subin »

Thanks for your reply.
In the JS example, CreateGlobalCEFApp; is called in the program file.
In my case I am using a dll (run time package) and need to know where to call CreateGlobalCEFApp.
I tried to call this with in a class of the package. However if gives exception when accessing it for the second time (GlobalCEFApp.StartMainProcess; is called again). Please help
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Retrun JS result Tchromium

Post by salvadordf »

CEF can only be initialized once per process.

Export 2 functions to initialize and finalize GlobalCEFApp. See the DLLBrowser demo.
subin
Posts: 20
Joined: Thu Sep 05, 2024 5:15 am

Re: Retrun JS result Tchromium

Post by subin »

Thanks for your reply.

IN my application I am using dll( runtime package). I created GlobalCEFApp in initialization section of a unit file of the library. Also called GlobalCEFApp.StartMainProcess; (without insde if statement) after creation of GlobalCEFApp. In finalization called DestroyGlobalCEFApp. However the code
TempJSCode := 'var testhtml = document.getElementById(' + quotedstr('ctl00_processingRequestPanel') +
'.innerHTML; ' + 'myextension.sendresulttobrowser(testhtml, ' + quotedstr(HTMLDOMELEMENT_MESSAGE_NAME) + ');';
fBrowser.ExecuteJavaScript(TempJSCode, 'about:blank', 0);

is not executing and the onprocessmessagerecived event is not invoking. Could you please help.

Thank you
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Retrun JS result Tchromium

Post by salvadordf »

https://github.com/salvadordf/CEF4Delphi/blob/66279dde4269ac4360d3475d1dd55fd56cc77c89/demos/Delphi_VCL/DLLBrowser/DLLBrowser.dpr#L31

Code: Select all

// CEF3 needs to be initialized and finalized outside the DLL's initialization and
// finalization sections. For this reason, you need to call InitializeCEF4Delphi
// after you load this DLL and you also need to call FinalizeCEF4Delphi before
// unloading this DLL.
subin
Posts: 20
Joined: Thu Sep 05, 2024 5:15 am

Re: Retrun JS result Tchromium

Post by subin »

Thanks for your reply.
I am using a runtime dll.
When I call procedure InitializeCEF4Delphi; stdcall; external 'XX.dll';, If fails to load the runtime dll when opening the IDE.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Retrun JS result Tchromium

Post by salvadordf »

Try loading the DLL with LoadLibrary and then use GetProcAddress for the functions.

CEF4Delphi, WebView4Delphi and WebUI4Delphi use those functions to avoid that issue.
subin
Posts: 20
Joined: Thu Sep 05, 2024 5:15 am

Re: Retrun JS result Tchromium

Post by subin »

Thanks for your reply. Just to know can't I implement InitializeCEF4Delphi and FinalizeCEF4Delphi with in the same dll. In my application I am using 2 different dlls. Can I implement these functions in one dll?
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Retrun JS result Tchromium

Post by salvadordf »

It's only allowed to initialize CEF once per process. There's no workaround for this feature.

Using DLLs to embed a browser is complicated because it's not possible to access variables or data between the main application and the code inside the DLL directly. Having multiple DLLs complicates things even more.
Post Reply