salvadordf / CEF4Delphi

CEF4Delphi is an open source project to embed Chromium-based browsers in applications made with Delphi or Lazarus/FPC for Windows, Linux and MacOS.
https://www.briskbard.com/forum/
Other
1.19k stars 363 forks source link

MacOS Js extension doesn't work in multiprocess mode #499

Closed bamsey2k1 closed 4 months ago

bamsey2k1 commented 5 months ago

Greetings :) I have wrote platform app based on CEF4Delphi and I've noticed an issue on MacOS platform.

JS Extension doesn't work when property GlobalCEFApp.SingleProcess := False;

it is working when GlobalCEFApp.SingleProcess := True.

My extension is like below:

TempExtensionCode := 'var ui;' + 'if (!ui)' + ' ui = {};' + '(function() {';
(... some functions ... ); TempExtensionCode := TempExtensionCode + '})();';

Extension is working in each case on Windows.

There is minor problem with resizing DevTools (Align := alRight) using splitter, it's not anchoring to the right side of the form. Zrzut ekranu 2024-02-2 o 07 42 42

Tested on latest stable release: https://github.com/salvadordf/CEF4Delphi/releases/tag/120.0.6099.234

salvadordf commented 5 months ago

Are you using Delphi or Lazarus?

MacOS has several projects and the JS extension runs in the render process. Move the code in GlobalCEFApp.OnWebKitInitialized to the render project.

I would recommend creating a Windows demo with a different executable for the CEF subprocesses. Move the GlobalCEFApp.OnWebKitInitialized code to the subprocess project and check if it works in Windows.

bamsey2k1 commented 5 months ago

I'm using Lazarus which is installed on Mac. I've modified ExternalPumpBrowser demo to show You how I made it. ExternalPumpBrowser.zip

In this example You will find both inconveniences I've mentioned above.

salvadordf commented 5 months ago

I just uploaded a new demo called JSExtensionSubProcess.

It has a JSExtension_sp project that creates the executable for the CEF subprocesses and I moved all the code from GlobalCEFApp.OnWebKitInitialized to that project.

In the case of MacOS, you should move the code in GlobalCEFApp.OnWebKitInitialized to the AppHelper project.

Also try calling Chromium1.ShowDevTools with a nil value for the aDevTools parameter. This will create the devtools in a new window handled by CEF.

bamsey2k1 commented 4 months ago

So I have moved GlobalCEFApp.OnWebKitInitialized to AppHelper and it worked :) ShowDevTools with a nil value also worked which is fine, but shame it doesn't work like on Windows. Nevertheless thank for help in solving my issue :)