Page 1 of 2

Conversion from CEF3 to CEF4Delphi

Posted: Sat Aug 14, 2021 10:39 am
by mrtnlowr
Hi,

After Google recently stopped responding to API requests from CEF3 I've tried to port my app over to CEF4Delphi. Although I've followed the examples in the Demos (SimpleBrowser2, SubProcess, MiniBrowser & SchemeRegistrationBrowser) as best I can I'm still struggling to make progress.
My app uses a browser hosting form created on demand at which time the GlobalCEFApp is created and initialised. I use a separate EXE file the browser processes, register a custom scheme and provide a resource handler (in the main EXE file) to load a small webapp from the main EXE's resources. Although the resource handler methods are called successfully TChromium.OnLoadEnd is never called and nothing is rendered. Even right-clicking on the browser window does not produce a context menu. Where am I going wrong? :)

Hoping someone can help as I'm getting a little frustrated.

M
PS Not sure where this belongs - it's an issue for me but not in a bug CEF4Delphi.

Re: Conversion from CEF3 to CEF4Delphi

Posted: Sat Aug 14, 2021 11:15 am
by salvadordf
Hi,

It's difficult to know what's happening without some code that I can run in my computer to reproduce this issue.

Perhaps the "ReadResponse" and "ProcessRequest" functions in the resource handler are not returning the right value when the resource is not available or when there's no data.

Compare those functions with the THelloScheme class in the SchemeRegistrationBrowser demo.

Read this for more information about the resource handler :
https://magpcss.org/ceforum/apidocs3/projects/(default)/CefResourceHandler.html

Note : The deprecated methods in CefResourceHandler work fine but the new methods have issues.

Re: Conversion from CEF3 to CEF4Delphi

Posted: Sat Aug 14, 2021 3:59 pm
by mrtnlowr
Hi,

It looks like the Render process is crashing after ReadResponse returns but I've no idea why or where.
I'll try reducing the code to its simplest and uploading for you.

M

Re: Conversion from CEF3 to CEF4Delphi

Posted: Sat Aug 14, 2021 6:20 pm
by mrtnlowr
Hi,

Spent another hour or so on this but no progress. Here's the code.

M

Re: Conversion from CEF3 to CEF4Delphi

Posted: Sun Aug 15, 2021 12:53 pm
by salvadordf
I can't build that project because chrome.lfm is missing but I would make some suggestions.
  • Use the methods of TChromium instead of using ICefBrowser instances in global variables. Those methods check that the browser is initialized and they also validate all interfaces before using them.
  • Move all the functions from the GMAPILink unit to the unit with the TChromium component to eliminate some of the global variables and to use TChromium methods directly.
  • It's not recommended to cast CEF interfaces as integers to pass them as pointers in messages.
  • The CEF subprocess must register the custom scheme too.
  • If the render process is crashing you can disable the GlobalCEFApp.BrowserSubprocessPath assignment and then set GlobalCEFApp.SingleProcess to True. The single process mode is only intended for debugging purposes and it will allow you to debug the code that is normally executed in the render process. Ignore shutdown issues in single process mode because they are caused by a known CEF problem.
The following attachment is a modified SchemeRegistrationBrowser demo that uses a different EXE for the subprocesses.

Re: Conversion from CEF3 to CEF4Delphi

Posted: Mon Aug 16, 2021 9:44 am
by mrtnlowr
Salvador,

Many thanks for your suggestions. I've implemented all of them but they make no difference. LoadEnd is still not called and the render process still crashes. Unfortunately setting SingleProcess to true didn't help as, according to the assembler window, the the program hung somewhere in libcef making debugging the code impossible. It's probably something very simple in my code but I guess I'm just too close. I'll keep looking.

I'm attaching Chrome.lfm just in case :)

M

Re: Conversion from CEF3 to CEF4Delphi

Posted: Tue Aug 17, 2021 10:47 am
by mrtnlowr
Hi,

Are there any events between ReadResponse and LoadStart where I might place a breakpoint to follow what happens?

M

Re: Conversion from CEF3 to CEF4Delphi

Posted: Tue Aug 17, 2021 12:35 pm
by salvadordf
Try the SchemeRegistrationBrowser demo and you will see that the usual TChromium events are triggered when the page is loaded :
TChromium.OnLoadEnd, TChromium.OnLoadingStateChange, TChromium.OnResourceResponse, etc.

Please, use the code from the SchemeRegistrationBrowser demo as a template for your application.

Re: Conversion from CEF3 to CEF4Delphi

Posted: Tue Aug 17, 2021 2:43 pm
by mrtnlowr
Hi,

OK, reverted back to SchemeRegistrationBrowser as template and implemented those event handlers but the render process still crashes.
Here's the progress memo content:

[0817/145244.383:FDR:TfmChrome] CreateBrowser called. (result = 1)
[0817/145244.723:FDR:TfmChrome] LoadURL called. (result = 0)
[0817/145244.723:FDR:TfmChrome] LoadingStateChange: isLoading = True
[0817/145245.237:FDR:TfmChrome] Browser(1) BeforeBrowse called. 'fdrtp://fdr/hello.html'
[0817/145245.240:FDR:TMapSchemeHandler] MapSchemeHandler.Create called
[0817/145245.242:FDR:TMapSchemeHandler] MapSchemeHandler.AfterConstruction called
[0817/145245.245:FDR:TMapSchemeHandler] MapSchemeHandler.ProcessRequest called
[0817/145245.246:FDR:TMapSchemeHandler] MapSchemeHandler.GetResponseHeaders called
[0817/145245.248:FDR:TfmChrome] ResourceResponse called.
[0817/145245.250:FDR:TMapSchemeHandler] MapSchemeHandler.ReadResponse called
[0817/145245.252:FDR:TMapSchemeHandler] MapSchemeHandler.ReadResponse called
[0817/145245.257:FDR:TfmChrome] Browser(1) url: 'fdrtp://fdr/hello.html' status: 1 [863 bytes].
[0817/145245.259:FDR:TMapSchemeHandler] MapSchemeHandler.Destroy called
[0817/145259.830:FDR:TfmChrome] LoadingStateChange: isLoading = False
[0817/150031.607:FDR:TfmChrome] Browser(1) [Product Version: 92.0.4515.131] Render process terminated! (status = 2).

Apologies for being a nuisance but I really don't know where to look for a solution.
Thanks for you help.

M

Re: Conversion from CEF3 to CEF4Delphi

Posted: Wed Aug 18, 2021 2:41 pm
by salvadordf
It's very important to use the TChromium procedures instead of making copies of CEF interfaces because they can only be used when CEF allows us to use them.

In fact, if we keep one of those variables for too long we may have shutdown issues. TChromium makes a lot of validity and initialization checks to avoid crashes and shutdown issues.

I just updated CEF4Delphi and there's a new SchemeRegistrationBrowser_subprocess demo that loads test.html which includes a Google Maps example. You'll need to edit test.html with your API key to make it work.

Please, modify SchemeRegistrationBrowser_subprocess to use the HTML file in the resources instead of opening a local file.