Window.close() differing behavior in Firefox Quantum versus previous versions

Hi AMO,

We’re the team that makes the OneNote Web Clipper (https://addons.mozilla.org/en-US/firefox/addon/onenote-clipper/). Some of users have switched to Firefox Quantum and discovered a “bug”.

Our log-in flow opens a popup window, listens for a redirect after log-in, grabs the credentials, and then closes the window. After switching to Quantum, the Window no longer closes, and the console shows the error message: “Scripts may not close windows that were not opened by script.”

The documentation is clear here (https://developer.mozilla.org/en-US/docs/Web/API/Window/close) that closing a window via JS that wasn’t opened via JS is not possible. While we are still determining where in our code we are closing this (via JS or JS that exists on the page that ends up being loaded), we still thought we should report it, as this behavior is different than previous versions of Firefox and differs from Chrome as well.

I presume the popup window you open is loaded from the add-on, i.e from a moz-extension:// URL.
I agree the restriction to not being able to close its own window does not make much sense if you are running in an add-on. It obliges the content code to send a message to the add-on background to close this window, just making things more complex than they should be.

The moz-extension:// page should be able to use the browser.windows API directly, as it has the same privileges as the background page.

Though I agree, that being able to call window.close() would be nicer.

You’re correct. I did not realize that calling windows.getCurrent() from an add-on content would return the right id to close that window. So this would work:

browser.windows.getCurrent()
  .then((window)=>{
    browser.windows.remove(window.id);
  });

A bit more verbose than window.close() but still acceptable.

No need to call browser.windows.getCurrent(). You can use directly the property WINDOW_ID_CURRENT, it is faster and shorter.
browser.windows.remove(browser.windows.WINDOW_ID_CURRENT);

1 Like