Process message isn't handled by CEF renderer process while

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.

Process message isn't handled by CEF renderer process while

Postby denisv » Fri Feb 12, 2021 5:07 pm

Hi, all.

I'm upgrading my application from CEF1, where it was single process, to CEF3 and I'm dealing with some process synchronization issues.

I have this implementation of CEF in my application:

Application creates the browser, using CreateBrowser. This way the browser process is actually my application process.

Then I have a exe that is ran as browser subprocess, I set it in settings when I call CefInitialize.

My process instantiates my app class, that inherits from CefApp and CefRenderProcessHandler and calls CefExecuteProcess. Then in my client app class on OnContextCreated I create an object with functions, which are handled by my custom written class inheriting from CefV8Handler. This way when functions from that object are invoked from the web page JS, it goes to CefV8Handler::Execute where I return a result via retval parameter of Execute().

Now the real problem is that web page interacts with my application, and for that purpose I need properties defined in application to end up in my implementation of renderer process. This I achieve by sending process message from browser process, where my application properties sit, to renderer process, where I keep a cache for those properties, and my CefV8Handler has access to them.

Now the issue is that when renderer process is blocked by JS execution, OnProcessMessageReceived is called only after JS execution is done, even if I send a message in the middle of JS execution. This might cause issues, if I'm sending a property, while JS that uses that property is being executed.

Just an extremely simplified example to help describing the problem. I have a button in my web page that runs the following code, that runs for about 10 seconds:
Code: Select all
for(int i = 0; i < 10000000000; i++) {}
var prop = MyObj.Property
alert(prop);


So I click on the button to start executing that code, after that in my application I perform an action that updates the property, that causes browser process to send process message to renderer process with the new value of property, but since JS is executing OnProcessMessageReceived is not called on renderer side. So prop receives an old value of Property, and only after the code is executed OnProcessMessageReceived is called on renderer process and next call to MyObj.Property will return a new value.

Now I know JS is single thread, however CEF obviously is not, so is there any work around for this? Can message be handled by any unblocked thread on renderer process and then in my CefV8Handler I can read the value from that thread? Or any other way of sending message to renderer process, which can be processed while it's blocked with JS execution?

P.S.

I do realize there is an async solution for that, where callback function is passed to my function, then my handler sends a message to browser process, which then sends back a message with the property value to renderer process, and then I invoke the callback function with the result. Something like that:

Code: Select all
MyProp.GetProperty(
function(prop)
{
  code that does something with prop
});


But that would require a 3-rd party web site that integrates with my application to change their JS side, which I want to avoid at all costs, and I want them to be able to access my properties as they did with CEF1 implementation by directly invoking the getter:

Code: Select all
var prop = MyObj.Property;


Thanks in advance,
Denis.
denisv
Techie
 
Posts: 12
Joined: Fri Feb 12, 2021 5:02 pm

Re: Process message isn't handled by CEF renderer process wh

Postby magreenblatt » Mon Feb 15, 2021 12:06 pm

It sounds like you understand the situation pretty well. Asynchronous execution is the recommended way to go.

Can message be handled by any unblocked thread on renderer process and then in my CefV8Handler I can read the value from that thread? Or any other way of sending message to renderer process, which can be processed while it's blocked with JS execution?

You would need to use something like synchronous XHR, which is not recommended.
magreenblatt
Site Admin
 
Posts: 12406
Joined: Fri May 29, 2009 6:57 pm

Re: Process message isn't handled by CEF renderer process wh

Postby denisv » Mon Feb 15, 2021 1:33 pm

Yep, I was afraid that would be the answer.

Well, I know the risks, so I went for synchronous named pipe between browser and renderer processes.Currently I don't see how this can go wrong, I mean if my application's main GUI thread (also browser process main thread in this case), which is hosting CEF, is blocked, then in any case the window container of CEF is blocked, so I might as well hang the rendered process on a synchronous pipe read, won't make the situation any worse!
denisv
Techie
 
Posts: 12
Joined: Fri Feb 12, 2021 5:02 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot], ndesktop, richardmgoodin and 39 guests