Skip to content

Instantly share code, notes, and snippets.

@vladikoff
Last active March 9, 2018 18:35
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 vladikoff/808c1c6477f0090840e54144c23b803e to your computer and use it in GitHub Desktop.
Save vladikoff/808c1c6477f0090840e54144c23b803e to your computer and use it in GitHub Desktop.

From https://bugzilla.mozilla.org/show_bug.cgi?id=1443749#c1

ISTM that notes is calling sidebarAction.open all the time. You should first check if it is open by calling sidebarAction.isOpen.

browser.browserAction.onClicked.addListener(() => {
  browser.sidebarAction.isOpen({}).then((isOpen) => {
    if (! isOpen) {
      browser.sidebarAction.open();
    }
  });
});

and

browser.contextMenus.onClicked.addListener((info) => {
  /**
   * If the `isOpen` API is available then use it. If we don't use that in Firefox 60+ then
   * the sidebar will flicker and cause all sorts of bugs.
   *
   * Opening the sidebar triggers `isEditorReady`.
   *
   * Ref: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/sidebarAction/isOpen
   */
  if (browser.sidebarAction.hasOwnProperty('isOpen')) {
    browser.sidebarAction.isOpen({}).then((isOpen) => {
      if (! isOpen) {
        browser.sidebarAction.open();
      }
      // then send selection text to Editor.js once editor instance is initialized and ready
      sendSelectionText(info.selectionText);
    });
  } else {
    browser.sidebarAction.open();
    // then send selection text to Editor.js once editor instance is initialized and ready
    sendSelectionText(info.selectionText);
  }
});

Causes: Error: sidebarAction.open may only be called from a user input handler background.js:255:9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment