OnContextCreated - never called

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

OnContextCreated - never called

Postby Staxcelrom » Wed Jun 29, 2022 2:49 pm

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?
Staxcelrom
Expert
 
Posts: 206
Joined: Wed Jan 26, 2022 8:20 am

Re: OnContextCreated - never called

Postby magreenblatt » Wed Jun 29, 2022 4:38 pm

Did you implement CefApp::GetRenderProcessHandler and pass the CefApp instance to CefExecuteProcess?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: OnContextCreated - never called

Postby Staxcelrom » Thu Jun 30, 2022 4:37 am

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;
   }
}
Staxcelrom
Expert
 
Posts: 206
Joined: Wed Jan 26, 2022 8:20 am

Re: OnContextCreated - never called

Postby magreenblatt » Thu Jun 30, 2022 5:54 am

You need to implement OnContextCreated in my_CEF__application_class, not my_CEF__browser
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: OnContextCreated - never called

Postby amaitland » Thu Jun 30, 2022 5:58 am

Your entry point also looks incorrect.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: OnContextCreated - never called

Postby Staxcelrom » Thu Jun 30, 2022 6:12 am

magreenblatt wrote:You need to implement OnContextCreated in my_CEF__application_class, not my_CEF__browser


Thank you! It works!
Staxcelrom
Expert
 
Posts: 206
Joined: Wed Jan 26, 2022 8:20 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 47 guests