OnContextCreated never called on primary process in off-screen rendering mode
Closed this issue · 4 comments
Describe the bug
I have a functional application based on CEF 125. It set in off-screen with a secondary process. Now, I want to integrate JS. I followed this link, but the OnContextCreated
is never called by my primary process. If I apply the same changes for the secondary process, its OnContextCreated() is called, but this does not interest me since I want to manage JS by my primary process.
I think OnContextCreated cannot be called in off-screen rendering and as consequence GetMainFrame()->GetV8Context() is always nullptr.
To Reproduce
My Primary Process
The primary process inherited from the following handlers See full code here:
class GDCef
{
class Impl: public CefLifeSpanHandler,
public CefClient,
public CefApp,
public CefBrowserProcessHandler
note: m_impl is my application, I add to create subclass to avoid double RefCounter: one by CEF, the second for Godot. This works well.
CefSettings of the primary process are configured See full code here:
- windowless_rendering_enabled = true
- SetAsWindowless(0)
- no_sandbox = true
- browser_subprocess_path = valid canonical path to secondary process
The init is called here and when I create my browser, CefApp is well passed as argument :
- https://github.com/Lecrapouille/gdcef/blob/8fb632a9575a6ffe4c590ede09a3caf7aee7f456/addons/gdcef/gdcef/src/gdcef.cpp#L503
- calling https://github.com/Lecrapouille/gdcef/blob/8fb632a9575a6ffe4c590ede09a3caf7aee7f456/addons/gdcef/gdcef/src/gdbrowser.cpp#L196
My Browser class is defined as See full code here:
class GDBrowserView
{
class Impl: public CefClient,
public CefRenderHandler,
public CefLoadHandler,
public CefAudioHandler
Ideally, I would have preferred the browser manages its own V8 context, but it is said not to do that (why ? no reasons given!). I also give a try without success. So Currently the context always return nullptr even if the page has been loaded;
m_browser->GetMainFrame()->GetV8Context()
Secondary Process
The secondary process is defined. See here:
class GDCefBrowser : public CefApp,
public CefBrowserProcessHandler
If changed to:
class GDCefBrowser: public CefApp,
public CefBrowserProcessHandler,
public CefRenderProcessHandler
{
private: // CefApp methods
// -------------------------------------------------------------------------
virtual CefRefPtr<CefBrowserProcessHandler>
GetBrowserProcessHandler() override
{
return this;
}
virtual CefRefPtr<CefRenderProcessHandler>
GetRenderProcessHandler() override
{
return this;
}
private: // CefBrowserProcessHandler methods
// -------------------------------------------------------------------------
virtual void OnContextInitialized() override;
private: // CefRenderProcessHandler methods
// -------------------------------------------------------------------------
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) override;
private:
IMPLEMENT_REFCOUNTING(GDCefBrowser);
};
The OnContextCreated is called.
Expected behavior
- Primary process does not have OnContextCreated called.
- Browser of primary process does not have OnContextCreated called.
- Secondary process has OnContextCreated called has expected.
Versions (please complete the following information):
- OS: Debian 12
- CEF Version: 125
Additional context
SHA1 c6125cda14d663aa48917dfd5893a9c35b7bfaa8 https://github.com/Lecrapouille/gdcef/tree/godot-4.x
Primary process does not have OnContextCreated called.
OnContextCreated is only called in the renderer process.
"renderer process" == secondary process (the exe called from CefSettings::browser_subprocess_path) ? But how the primary process gets the V8 context ? This means in offscreen mode it is not possible to interact with HTML/JS document ?
Thank you for the documentation, but I already knew it. I felt it could be more beginner-friendly in some aspects. For example, the separation of business logic into a secondary app rather than the primary process can be a bit challenging to grasp for newcomers. Including some UML diagrams, particularly sequence diagrams, might help clarify these concepts. With the help of AI giving me code and revisiting an older project BLUI, I was able to understand that the subprocess is responsible for rendering. Initially, I had assumed the rendering was handled by the main process.