IPC message from renderer to browser process not sending?

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.

IPC message from renderer to browser process not sending?

Postby bamilab » Mon Oct 26, 2020 2:34 pm

Hey guys,

I'm trying to send some data from the renderer process to the browser process. The other way around seems to be working fine. However, when I try to send some back, the message never gets received.

Here is the relevant code that is trying to send the message:
Code: Select all
      CefRefPtr<CefProcessMessage> msg = CefProcessMessage::Create("eval-js-result");
      CefRefPtr<CefListValue> msg_args = msg->GetArgumentList();
      if ( !result ) {fprintf(stderr, "error\n");

         CefString error_msg = "error";//bw_cef_v8exc_to_string( exception );

         // The first parameter specifies the ID of the script that has executed
         msg_args->SetInt( 0, script_id );
         // The second parameter specifies whether or not an error has resulted
         msg_args->SetBool( 1, false );
         // The third parameter specifies the error message
         msg_args->SetString( 2, error_msg );
      }
      else {

         CefString result_string = ret_val->GetStringValue();

         // The first parameter specifies the ID of the script that has executed
         msg_args->SetInt( 0, script_id );
         // The second parameter specifies whether or not an error has resulted
         msg_args->SetBool( 1, true );
         // The third parameter specifies the result formatted as a string
         msg_args->SetString( 2, result_string );
      }

      // Send the message back to the browser process
      browser->GetMainFrame()->SendProcessMessage( PID_BROWSER, msg );


and here is my OnProcessMessageReceived function, that doesn't get called after sending this particular message unfortunately.

Code: Select all
   virtual bool OnProcessMessageReceived(
      CefRefPtr<CefBrowser> browser,
      CefRefPtr<CefFrame> frame,
      CefProcessId source_process,
      CefRefPtr<CefProcessMessage> message
   ) override {

      // The message to execute some javascript, and return its output
      if ( message->GetName() == "eval-js" ) {
         int script_id = message->GetArgumentList()->GetInt( 0 );
         CefString js = message->GetArgumentList()->GetString( 1 );

         this->eval_js( browser, frame, js, script_id );

         return true;
      }
      // The message to reveal the result of some javascript code
      else if ( message->GetName() == "eval-js-result" ) {
         fprintf(stderr, "eval-js-result\n");
         int script_id = message->GetArgumentList()->GetInt( 0 );
         bool success = message->GetArgumentList()->GetBool( 1 );
         CefString result = message->GetArgumentList()->GetString( 2 );

         fprintf(stderr, "Test: %s\n", result.ToString().c_str());

         return true;
      }
      else
         fprintf(stderr, "Unknown process message received: %s\n", message->GetName() );

      return false;
   }


Got any ideas?

Thank you.
bamilab
Techie
 
Posts: 14
Joined: Fri Oct 23, 2020 12:32 pm

Re: IPC message from renderer to browser process not sending

Postby magreenblatt » Mon Oct 26, 2020 2:37 pm

What OS and CEF version? What renderer process method are you sending the message from?
magreenblatt
Site Admin
 
Posts: 12383
Joined: Fri May 29, 2009 6:57 pm

Re: IPC message from renderer to browser process not sending

Postby bamilab » Mon Oct 26, 2020 2:46 pm

The first piece of code is actually part of eval_js within OnProcessMessageReceived.

I'm using 84.3.8+gc8a556f+chromium-84.0.4147.105_windows64, if I remember correctly I got it using vcpkg.
bamilab
Techie
 
Posts: 14
Joined: Fri Oct 23, 2020 12:32 pm

Re: IPC message from renderer to browser process not sending

Postby magreenblatt » Mon Oct 26, 2020 3:18 pm

bamilab wrote:The first piece of code is actually part of eval_js within OnProcessMessageReceived.

Do you mean CefRenderProcessHandler::OnProcessMessageReceived? CefClient::OnProcessMessageReceived is only called in the browser process.
magreenblatt
Site Admin
 
Posts: 12383
Joined: Fri May 29, 2009 6:57 pm

Re: IPC message from renderer to browser process not sending

Postby bamilab » Mon Oct 26, 2020 3:53 pm

Hmm... Yes I mean CefRenderProcessHandler::OnProcessMessageReceived.

Now that you mention it, CefRenderProcessHandler has the word "Render" in it... :roll: :shock:

Ok I'll try implementing the OnProcessMessageReceived in CefClient. :)
bamilab
Techie
 
Posts: 14
Joined: Fri Oct 23, 2020 12:32 pm

Re: IPC message from renderer to browser process not sending

Postby bamilab » Mon Oct 26, 2020 4:02 pm

It worked. 8-) Thanks :)
bamilab
Techie
 
Posts: 14
Joined: Fri Oct 23, 2020 12:32 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 59 guests