From 23b9e0ec810580f889762cfe95f8e5b50f9d0a19 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 27 Jan 2016 16:25:46 +0100 Subject: [PATCH] Workaround Firefox bug showing beforeunload twice --- notebook/static/notebook/js/notebook.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/notebook/static/notebook/js/notebook.js b/notebook/static/notebook/js/notebook.js index 3a722b587..3847ce1c7 100644 --- a/notebook/static/notebook/js/notebook.js +++ b/notebook/static/notebook/js/notebook.js @@ -67,6 +67,8 @@ define(function (require) { this.last_modified = null; // debug 484 this._last_modified = 'init'; + // Firefox workaround + this._ff_beforeunload_fired = false; // Create default scroll manager. this.scroll_manager = new scrollmanager.ScrollManager(this); @@ -314,6 +316,17 @@ define(function (require) { if (kill_kernel) { that.session.delete(); } + if ( utils.browser[0] === "Firefox") { + // Workaround ancient Firefox bug showing beforeunload twice: https://bugzilla.mozilla.org/show_bug.cgi?id=531199 + if (that._ff_beforeunload_fired) { + return; // don't show twice on FF + } + that._ff_beforeunload_fired = true; + // unset flag immediately after dialog is dismissed + setTimeout(function () { + that._ff_beforeunload_fired = false; + }, 1); + } // if we are autosaving, trigger an autosave on nav-away. // still warn, because if we don't the autosave may fail. if (that.dirty) {