Skip to content

Commit

Permalink
Add Firefox Beacon bug workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
TatuJLund committed Jul 3, 2024
1 parent fadabed commit a29f618
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class VaadinCreateUI extends UI implements EventBusListener, HasI18N {
@Override
protected void init(VaadinRequest request) {
getPage().setTitle("Vaadin Create 23'");
addFirefoxBrowserCloseWorkaround();
if (!getAccessControl().isUserSignedIn()) {
showLoginView();
} else {
Expand All @@ -69,6 +70,21 @@ protected void init(VaadinRequest request) {
eventBus.registerEventBusListener(this);
}

// Vaadin 8 actually has page hide listener and eager closing of UI's, but
// there is a bug in Firefox's sending Beacon upon browser close, hence
// adding a workaround to detect closing of the Browser old fashioned way.
// https://bugzilla.mozilla.org/show_bug.cgi?id=1609653
private void addFirefoxBrowserCloseWorkaround() {
if (getPage().getWebBrowser().isFirefox()) {
getPage().getJavaScript()
.execute("function closeListener() { catchClose(); } "
+ "window.addEventListener('beforeunload', closeListener);");
getPage().getJavaScript().addFunction("catchClose", arguments -> {
close();
});
}
}

private void showLoginView() {
setContent(new LoginView(getAccessControl(), e -> onLogin()));
}
Expand Down

0 comments on commit a29f618

Please sign in to comment.