Callback function window.cefClient is not found sporadically

Having problems with building or using the JCEF Java binding? Ask your questions here.

Callback function window.cefClient is not found sporadically

Postby Easy1 » Fri May 07, 2021 4:34 am

Hello @all!

We are using the JCEF version 4147 and one of our customer has sproadic problems with calling the callback window.cefClient.
The callback function window.cefClient cannot be called or is not attached to the window sporadically in the javascript content.
Unfortunately we don't know why this problem occurs and how to find out what happens to this callback function in the situation where the callback call fails.

Following error occurs:
Code: Select all
INFO:CONSOLE(74)] "Uncaught TypeError: window.cefQuery is not a function"

I have already looked in the JCEF forum and found the following two entries (viewtopic.php?f=17&t=14380 and https://magpcss.org/ceforum/viewtopic.php?f=6&t=17511),
where it is explained that there might be needed some changes in the JCEF code.
However we don't even know what the real problem ist, and why the callback function cannot be called sometimes.

Any clue how to find out why sometimes the callback function is not found and how to fix it?
Is there any possibility to get more info in the javascript context, to get to know why this problem occurs sporadically?
Are there any planned/known transition periods, in which this window.cefQuery is not available/callable (navigation or something similar)?

Thanks in advance!
Easy1
Newbie
 
Posts: 8
Joined: Mon Feb 20, 2017 8:23 am

Re: Callback function window.cefClient is not found sporadic

Postby Easy1 » Wed May 12, 2021 9:23 am

After some analysis we came to the conclusion, that the problem might occur because the messageRouter was removed, even if we don't call the removeMessageRouter method (only when we close the browser instances, which is not the case when the problem occurs).
Is there any way to find out when a message router is removed? Maybe we can activate some logging?
Is there any possibility, that the org.cef.browser.CefMessageRouter.addHandler(CefMessageRouterHandler, boolean) method returns true, although the message router was not added successfully? Because if the error occurs, this addHandler method returns true but the first cefQuery call also fails. So we are not sure if the problem is because the handler was not added successfully or the handler is removed before the first cefQuery call.

Thank you very much!
Easy1
Newbie
 
Posts: 8
Joined: Mon Feb 20, 2017 8:23 am

Re: Callback function window.cefClient is not found sporadic

Postby magreenblatt » Wed May 12, 2021 9:25 am

Are you navigating at or around the time that cefQuery stops working?
magreenblatt
Site Admin
 
Posts: 10866
Joined: Fri May 29, 2009 6:57 pm

Re: Callback function window.cefClient is not found sporadic

Postby Phylanx » Fri May 14, 2021 2:35 am

Hello, Marshall!

Easy1 is on vacation today, so I'm answering.

We have this problem in two different usecases:

Usecase 1.: we open a page from another department of our company. We expect it to send a 'hey, we are here' like callback via htmlSendCommand so we know that it is ready.
In this case: yes, a navigation just recently happened.

Usecase 2.: we open a page from a third party company. When this page will be closed, we send a 'hey, is your feature dirty?' to it and expect it to respond via htmlSendCommand.
In this usecase we navigated and the page was stood open for some time.
Here the navigation happened some time before.

I attached small blackened (because of privacy/GDPR reasons) excerpt of the logs (combined of our products logfile which logs the communication with jcef and the jcef logs): Usecase1.txt and Usecase2.txt

Most time it works, but since the upgrade from 3325 to 4147 we get feedback by our customers that it sporadically does not work.
PS: We have implemented a javascript callback function 'htmlSendCommand' that basically wraps the window.cefQuery call for us.

Thanks in Advance,
Johann
Attachments
Usecase2.txt
(6.69 KiB) Downloaded 33 times
Usecase1.txt
(8.68 KiB) Downloaded 33 times
Phylanx
Expert
 
Posts: 143
Joined: Thu Aug 11, 2016 8:17 am

Re: Callback function window.cefClient is not found sporadic

Postby magreenblatt » Fri May 14, 2021 8:52 am

What JS event handler or logic are you using to trigger the htmlSendCommand call in each usecase?
magreenblatt
Site Admin
 
Posts: 10866
Joined: Fri May 29, 2009 6:57 pm

Re: Callback function window.cefClient is not found sporadic

Postby Phylanx » Mon May 17, 2021 1:59 am

Hi!

Thanks for the answer!

For registering our callbacks we use the JCEF callbacks "onAddressChange" and "onLoadEnd" to install our javaScript Callbacks (we do this everytime the callback comes, so multiple times. You can see this in the "installJavaScriptCallbacks" loggings).
As we see it the "htmlSendCommand" callback is installed even if the callback function doesn't work later.
The error is "TypeError: window.cefQuery is not a function" as if the cefQuery MessageRouter wasn't registered (which also was registered because we do it every time).

Triggering the htmlSendCommand happens in these ways:
1st Usecase:
We trigger a navigation from about:blank to the page of our product (which was implemented by another department, so I don't know the code very well).
When the JavaScript Code finished loading and initializing it should send an "initializeCompleted" callback (don't know if there's any JS EventHandler,... logic in between).
On Java side we wait for this callback so that we know that the page is ready to get further commands (e.g. login, SPA feature loading,...), but we don't get it because of the "Uncaught TypeError: window.cefQuery is not a function" error.

2nd Usecase:
We already loaded a third party page and the customer did his regular work on it.
When he wants to close the page (f.e. by closing the current window or pressing a button that triggers removing the browser UI from the JFrame and destroying the browser) we ask the 3rd party page if it is dirty. This works in the following way:
We register a function "MPAwillClose" which gets a string parameter.
The string parameter is the "isDirty" function name of the third party page which returns if it is dirty or not.
We call the "isDirty" function and call back "window.cefQuery" with the result.
On Java side the register logic and the JS Call to "MPAwillClose" all happens in the EventQueue.
Before destroying the browser we wait for the callback because we don't want the customer to lose unsaved data.
This callback with the "isDirty" result is missing because of the "Uncaught TypeError: window.cefQuery is not a function" error.
We also don't know if the callback worked before in this usecase.
We don't see a regular callback called (which could happen before closing to do some business logic communication between JS and Java), but sometimes a multiple "window.cefQuery is not a function" logging, so we guess that the problem was already there before.

We just implemented a test logic that tests the callback functionality right after registering our callbacks (by adding a direct callback in the install-JS-code itself).
Most times it works but in the problematic sporadic usecases even these callback calls don't come back.
The problem seems to be on the browser instance from the beginning of its lifecycle to the end (as if something didn't work on registering the callbacks).

We found a way to reproduce it (most times) but don't get the core out of the problem.
According to the boolean return value the MessageRouter registration always worked.
Is there any logging/... we can adapt to get more information on this usecase?
Where lies the usecase relevant code on CEF side (we already found the JCEF code)?

I'm sorry but I have to urge this problem.
Our customers already escalated the bug ticket.
Phylanx
Expert
 
Posts: 143
Joined: Thu Aug 11, 2016 8:17 am

Re: Callback function window.cefClient is not found sporadic

Postby magreenblatt » Mon May 17, 2021 10:55 am

I suggest that you avoid timing issues by registering the message router before creating the browser. That way it will always be available to the JavaScript code (see here and here in the native code). If this is a problem from a security standpoint (e.g. you only want to expose the callbacks on certain origins) then you can extend the native code logic to support an origin-based allowlist.
magreenblatt
Site Admin
 
Posts: 10866
Joined: Fri May 29, 2009 6:57 pm

Re: Callback function window.cefClient is not found sporadic

Postby Phylanx » Tue May 18, 2021 2:55 am

Hi!

Thanks for the answer!
We checked our Java Code and found out that we really create the browser before adding the message router to the CefClient.
We changed it but could reproduce the problem, so this didn't work for us :(

But we will take a look on the two native code snippets if we can find a problem there.
Thanks so far!

//EDIT:
We see that with the CEF Upgrade from 4147 to 4280 the handling of the MessageRouters changed.
Before the MessageRouters were added in the onRendererProcessCreated callbacks, after the upgrade they are created immediatly when creating the browser.
We'll give it a try, maybe we can add the single change regarding messageRouter and extra_info objects.
Phylanx
Expert
 
Posts: 143
Joined: Thu Aug 11, 2016 8:17 am

Re: Callback function window.cefClient is not found sporadic

Postby Phylanx » Tue May 18, 2021 5:44 am

Good news, we have a solution!

Thanks Marshall for the code places.
As we said in the last comment the changes at upgrade 4147 to 4280 did the trick.
We viewed this commit: https://github.com/chromiumembedded/jav ... d45e53d4b5

Then we applied only the changes affecting the Message Routing and that did the trick.
We could no longer reproduce the problematic behaviour.

Big big thanks for your help,
Phylanx
Phylanx
Expert
 
Posts: 143
Joined: Thu Aug 11, 2016 8:17 am


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 4 guests

cron