onBeforePopup returns true but still get a popup

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

onBeforePopup returns true but still get a popup

Postby yhe » Tue Mar 19, 2024 8:55 am

In the method onBeforePopup, I return true, based on the document, there will be no popup created. But I still get the following error:

"Unable to open window, please check Pop-ups blocker settings of your browser".

Some documents saying set the new browser to null and return true in onBeforePopup. But I cannot set the new browser to null because that is a new page I need to display.

Is there any way I can detect the popup event and disable it?

I'm using the version 122.1.10.
yhe
Newbie
 
Posts: 5
Joined: Thu Oct 13, 2022 8:26 am

Re: onBeforePopup returns true but still get a popup

Postby magreenblatt » Tue Mar 19, 2024 9:13 am

The error says that the popup was not created. What are you trying to do?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: onBeforePopup returns true but still get a popup

Postby KatrinaS » Wed Mar 20, 2024 10:47 pm

On the face of it, it seems like the correct behaviour, it's been blocked or rather cancelled, OP if you extend CefLoadHandlerAdapter and overide onLoadError, add that LoadHandler to the CefBrowser and you can detect all the errors coming out of the client (dump um to System.error in you Dev environment to see what it says about this particular error, then you can detect specifics) and ignore or whatever as you see fit,, perhaps, maybe :D
KatrinaS
Mentor
 
Posts: 83
Joined: Tue Jul 04, 2023 6:30 pm

Re: onBeforePopup returns true but still get a popup

Postby yhe » Mon Apr 08, 2024 8:06 am

Thanks for your reply.

I have a JcefControl class that creates a CefClient and adds the LifeSpanHandler to it: cefClient.addLifeSpanHandler(new JcefLifeSpanHandler(this));

In JcefLifeSpanHandler I implement the onBeforePopup

public boolean onBeforePopup(CefBrowser browser, CefFrame frame, String targetUrl, String targetFrameName) {

jcefCntrl.createBrowser(targetUrl, targetFrameName);

return true;
}

In JcefControl I have createBrowser method:
public void createBrowser(String url, String title) {
CefBrowser browser = cefClient.createBrowser(url, useOSR, isTransparent);
}

First I call the createBrowser to open the first page, and that is fine. But if I click a URL on the first created browser page, window.open(secondURL) gets called which triggers the createBrowser called from callback onBeforePopup, even it returns true, I get the error popup saying cannot open but the browser acturally is created and opened.

I just wonder is any way to get rid of the popup.

Thank you very much.
yhe
Newbie
 
Posts: 5
Joined: Thu Oct 13, 2022 8:26 am

Re: onBeforePopup returns true but still get a popup

Postby yhe » Mon Apr 08, 2024 8:59 am

Hi
As you mentioned I can extend CefLoadHandlerAdapter and override onLoadError. I've tried.

The onLoadError never gets called. I got a httpStatusCode 403 in the onLoadEnd method. But the page is opened.

Thanks.
yhe
Newbie
 
Posts: 5
Joined: Thu Oct 13, 2022 8:26 am

Re: onBeforePopup returns true but still get a popup

Postby KatrinaS » Tue Apr 09, 2024 8:29 pm

Strange how onLoadError isn't called, if it's cancelled (such as by cancelling a popup) one assumes it should receive ERR_ABORTED, do you want or not want the popup? There is another place you can intercept Requests, in CefRequestHandler, add a Handler to the CefBrowser overriding onBeforeBrowse return true to cancel / false to continue :)
KatrinaS
Mentor
 
Posts: 83
Joined: Tue Jul 04, 2023 6:30 pm

Re: onBeforePopup returns true but still get a popup

Postby yhe » Wed Apr 10, 2024 7:18 am

I do not want to the popup. Thanks!
yhe
Newbie
 
Posts: 5
Joined: Thu Oct 13, 2022 8:26 am

Re: onBeforePopup returns true but still get a popup

Postby KatrinaS » Wed Apr 10, 2024 12:41 pm

Yeah I thought you didn't want the popup but I wasn't sure :D Well you'd expect your original onBeforePopup to cancel it, the onBeforeBrowse method mentioned might do it :)
KatrinaS
Mentor
 
Posts: 83
Joined: Tue Jul 04, 2023 6:30 pm


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 136 guests

cron