Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpl/43de0a09b306d183be6bc2650093e985 to your computer and use it in GitHub Desktop.
Save rpl/43de0a09b306d183be6bc2650093e985 to your computer and use it in GitHub Desktop.
Avoid await on promiseDocumentFlushed when the browserAction is placed in the overflow menu
# HG changeset patch
# User Luca Greco <lgreco@mozilla.com>
# Date 1551125488 -3600
# Mon Feb 25 21:11:28 2019 +0100
# Node ID 42519936d019a00bd9ea52dcb6acf98a7545412b
# Parent 198cd4a81bf2afa7cc79360f90da7bc91218b76d
Bug 1285500 - Fix browser_ext_browserAction_popup intermittency when browserAction is placed in the overflow menu.
diff --git a/browser/components/extensions/ExtensionPopups.jsm b/browser/components/extensions/ExtensionPopups.jsm
--- a/browser/components/extensions/ExtensionPopups.jsm
+++ b/browser/components/extensions/ExtensionPopups.jsm
@@ -537,7 +537,7 @@ class ViewPopup extends BasePopup {
this.setBackground(this.background);
- let flushPromise = this.window.promiseDocumentFlushed(() => {
+ const getSizes = () => {
let win = this.window;
// Calculate the extra height available on the screen above and below the
@@ -555,7 +555,19 @@ class ViewPopup extends BasePopup {
bottom: Math.max(0, screenBottom - popupBottom),
top: Math.max(0, popupTop - win.screen.availTop),
};
- });
+ };
+
+ let flushPromise;
+
+ if (panel.id === "widget-overflow") {
+ // Get the popup sizes synchronously when the browserAction is placed in
+ // the overflow menu
+ getSizes();
+ } else {
+ // Wait for the ChromeWindow document to be flushed before retrieving
+ // the popup sizes when the browserAction is placed in the toolbar;
+ flushPromise = this.window.promiseDocumentFlushed(getSizes);
+ }
// Create a new browser in the real popup.
let browser = this.browser;
@@ -564,14 +576,16 @@ class ViewPopup extends BasePopup {
this.browser.swapDocShells(browser);
this.destroyBrowser(browser);
- await flushPromise;
+ if (flushPromise) {
+ await flushPromise;
- // Check if the popup has been destroyed while we were waiting for the
- // document flush promise to be resolve.
- if (this.destroyed) {
- this.closePopup();
- this.destroy();
- return false;
+ // Check if the popup has been destroyed while we were waiting for the
+ // document flush promise to be resolve.
+ if (this.destroyed) {
+ this.closePopup();
+ this.destroy();
+ return false;
+ }
}
if (this.dimensions) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment