CEF Browser instance closing while doing LoadURL.

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.

CEF Browser instance closing while doing LoadURL.

Postby DarthCoder » Wed Jan 30, 2013 12:54 pm

Got this weird issue when using CEF1 (chromium 19.0.1084.57) on windows.

I have a CEF browser window which is loaded with an URL through the CreateBrowserSync call itself, after I navigated to another link in the page, I am trying to navigate to another page using the browser->GetMainFrame()->LoadURL() call. I get the OnBeforeBrowse and OnContextCreated callbacks showing that the navigation is taking place. But then I get the OnBeforeClose callback indicating that the browser instance is closing. After I let it continue, the WebViewHost window closes and is no longer in the container dialog.

Now, I haven't gone into the full details of the url being loaded (debugging the JavaScript), but what can be the possible reasons for such a result? i.e. CEF browser window closing during navigation. I can think of one case where a window.close() call is present in the page some place and getting called.

The same URLs are loaded through our IE and gecko embedded browser without such an end result.
DarthCoder
Techie
 
Posts: 23
Joined: Mon Jun 20, 2011 4:57 am

Re: CEF Browser instance closing while doing LoadURL.

Postby magreenblatt » Wed Jan 30, 2013 12:58 pm

If you have symbols for CEF setting a breakpoint in OnBeforeClose and looking at the call stack might provide a useful hint.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CEF Browser instance closing while doing LoadURL.

Postby DarthCoder » Wed Jan 30, 2013 2:33 pm

Thanks Marshall, I have since found that there is a window.close() call in the web page code.

But the question is how come the window.close() has no effect in chrome (and Firefox) but closes triggers close in CEF? It seems that Firefox deliberately prevents windows not created through JavaScript from being closed through window.close call. I assume chrome also ignores it for the same reason. So why does CEF behave differently. Is there anything I can do If I want a behavior similar to Firefox or chrome?
DarthCoder
Techie
 
Posts: 23
Joined: Mon Jun 20, 2011 4:57 am

Re: CEF Browser instance closing while doing LoadURL.

Postby magreenblatt » Wed Jan 30, 2013 2:38 pm

Have you tried returning true from CefLifeSpanHandler::DoClose?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CEF Browser instance closing while doing LoadURL.

Postby DarthCoder » Thu Jan 31, 2013 1:37 am

I have tried implementing the DoClose and returning true from it for the main window. But it is not giving the desired result. The embedded CEF window is still closing.
DarthCoder
Techie
 
Posts: 23
Joined: Mon Jun 20, 2011 4:57 am

Re: CEF Browser instance closing while doing LoadURL.

Postby magreenblatt » Fri Feb 01, 2013 2:15 pm

You can disable window.close() all-together by setting CefBrowserSettings.javascript_close_windows_disallowed = true.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CEF Browser instance closing while doing LoadURL.

Postby DarthCoder » Mon Feb 04, 2013 1:11 pm

Yes, Thanks... :) I used the same solution ultimately.
Just to add, this flag does not disable window.close altogether. Even when it is set to true, if the window is created through script (Popups), it can still be closed. This is the exact desired behavior. i.e. it should not allow the window.close to work on main window, but windows created by DOM should can be closed.
DarthCoder
Techie
 
Posts: 23
Joined: Mon Jun 20, 2011 4:57 am

Re: CEF Browser instance closing while doing LoadURL.

Postby magreenblatt » Mon Feb 04, 2013 1:29 pm

DarthCoder wrote:Yes, Thanks... :) I used the same solution ultimately.
Just to add, this flag does not disable window.close altogether. Even when it is set to true, if the window is created through script (Popups), it can still be closed. This is the exact desired behavior. i.e. it should not allow the window.close to work on main window, but windows created by DOM should can be closed.

Thanks for the clarification, I'll update the documentation.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

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