You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CefBrowser_N.doClose() unexpectedly closes the host window #364
Original report by Anton Tarasov (Bitbucket: Anton Tarasov).
CefClient.doClose() javadoc says that:
If CEF created an OS window for the browser returning false will send an OS close
* notification to the browser window's top-level owner (e.g. WM_CLOSE on Windows, performClose:
* on OS-X and "delete_event" on Linux). If no OS window exists (window rendering disabled)
* returning false will cause the browser object to be destroyed immediately. Return true if the
* browser is parented to another window and that other window needs to receive close
* notification via some non-standard technique.
CefClient.doClose() may delegate to CefBrowser.doClose(). Here’s the impl from CefBrowser_N.doClose():
@Override
public synchronized boolean doClose() {
if (closeAllowed_) {
// Allow the close to proceed.
return false;
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// Trigger close of the parent window.
Component parent = SwingUtilities.getRoot(getUIComponent());
if (parent != null) {
parent.dispatchEvent(
new WindowEvent((Window) parent, WindowEvent.WINDOW_CLOSING));
}
}
});
// Cancel the close.
return true;
}
On canceling the close the method dispatches WINDOW_CLOSING. This contradicts the spec. Moreover, closeAllowed_ is false by default. This notification may cause the app to actually start application exit steps (when the event is dispatched to the app’s main frame, I experience this on MS Windows).
It’s not quite clear why JCEF needs to dispatch WINDOW_CLOSING even when closeAllowed_ is true. As the spec says, OS will deliver native closing message to the hosting window, that will make AWT generate all corresponding Java events.
This was likely an attempt to match the logic flow of CefLifeSpanHandler::DoClose. Perhaps a different approach would be better. Suggestions (including demo PR) are welcome.
I can confirm this. Is there a way to prevent window closing currently as this is quite problematic in app with multiple cef tabs as closing single tab in OSR just closes the whole thing
Activity
magreenblatt commentedon Jul 31, 2020
This was likely an attempt to match the logic flow of CefLifeSpanHandler::DoClose. Perhaps a different approach would be better. Suggestions (including demo PR) are welcome.
KlemenDEV commentedon Nov 3, 2025
I can confirm this. Is there a way to prevent window closing currently as this is quite problematic in app with multiple cef tabs as closing single tab in OSR just closes the whole thing
KlemenDEV commentedon Nov 3, 2025
It also seems that returning true for doClose does not close the browser in OSR mode
KlemenDEV commentedon Nov 3, 2025
Seems calling setCloseAllowed on browser object works as a workaround as then the parent window is not closed