Page 1 of 1

OnContextCreated - never called

PostPosted: Wed Jun 29, 2022 2:49 pm
by Staxcelrom
Hello,

I know what I'm doing wrong, but I can't figure out what exactly.

Code: Select all
class my_CEF__browser:public CefClient,..., public CefRenderProcessHandler
{
   void OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)  override
   {
      std::cout << "OnContextCreated" << std::endl;
   }
}


OnContextCreated - doesn't want to call.
Please tell me - what did i forget to do?

Re: OnContextCreated - never called

PostPosted: Wed Jun 29, 2022 4:38 pm
by magreenblatt
Did you implement CefApp::GetRenderProcessHandler and pass the CefApp instance to CefExecuteProcess?

Re: OnContextCreated - never called

PostPosted: Thu Jun 30, 2022 4:37 am
by Staxcelrom
magreenblatt wrote:Did you implement CefApp::GetRenderProcessHandler and pass the CefApp instance to CefExecuteProcess?


Yes, I did, perhaps incorrectly?

Code: Select all
class my_CEF__application_class : public CefApp, public CefBrowserProcessHandler, public CefRenderProcessHandler
{

public:

   CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() override
   {
      return this;
   }

   CefRefPtr<CefRenderProcessHandler > GetRenderProcessHandler() override
   {
      return this;
   }

   void OnContextInitialized() override
   {
      CEF_REQUIRE_UI_THREAD(); 
   }


private:
   IMPLEMENT_REFCOUNTING(my_CEF__application_class);
};



Code: Select all
int main_init()
{
//......

   CefRefPtr<my_CEF__application_callback_class> my_CEF__application_class_;     
   my_CEF__application_callback_class_ = new my_CEF__application_class;



   int ec = CefExecuteProcess(args, my_CEF__application_class_.get(), sandbox_info);

   bool my_status_CefInitialize = CefInitialize(args, settings, my_CEF__application_class_.get(), sandbox_info);   
}




But, OnContextCreated is still not called:

Code: Select all
class my_CEF__browser:public CefClient,..., public CefRenderProcessHandler
{
   void OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context)  override
   {
      std::cout << "OnContextCreated" << std::endl;
   }
}

Re: OnContextCreated - never called

PostPosted: Thu Jun 30, 2022 5:54 am
by magreenblatt
You need to implement OnContextCreated in my_CEF__application_class, not my_CEF__browser

Re: OnContextCreated - never called

PostPosted: Thu Jun 30, 2022 5:58 am
by amaitland
Your entry point also looks incorrect.

Re: OnContextCreated - never called

PostPosted: Thu Jun 30, 2022 6:12 am
by Staxcelrom
magreenblatt wrote:You need to implement OnContextCreated in my_CEF__application_class, not my_CEF__browser


Thank you! It works!