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

**URL:** <https://discourse.mozilla.org/t/window-close-differing-behavior-in-firefox-quantum-versus-previous-versions/23403>\
**Category:** Development\
**Created:** [December 13, 2017, 5:22pm UTC](https://discourse.mozilla.org/t/window-close-differing-behavior-in-firefox-quantum-versus-previous-versions/23403 "2017-12-13T17:22:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishaalkal](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/vishaalkal/32/23253_2.png) [@vishaalkal](https://discourse.mozilla.org/u/vishaalkal)\
**Post date:** [December 13, 2017, 5:22pm UTC](https://discourse.mozilla.org/t/window-close-differing-behavior-in-firefox-quantum-versus-previous-versions/23403/1 "2017-12-13T17:22:20Z")

</div>

Hi AMO,

We’re the team that makes the OneNote Web Clipper ([https://addons.mozilla.org/en-US/firefox/addon/onenote-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](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.

---

<div class="post-metadata">

**Author:** ![mig](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/mig/32/30725_2.png) [@mig](https://discourse.mozilla.org/u/mig)\
**Post date:** [December 13, 2017, 5:37pm UTC](https://discourse.mozilla.org/t/window-close-differing-behavior-in-firefox-quantum-versus-previous-versions/23403/2 "2017-12-13T17:37:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![freaktechnik](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/freaktechnik/32/37766_2.png) [@freaktechnik](https://discourse.mozilla.org/u/freaktechnik)\
**Post date:** [December 13, 2017, 7:01pm UTC](https://discourse.mozilla.org/t/window-close-differing-behavior-in-firefox-quantum-versus-previous-versions/23403/3 "2017-12-13T19:01:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mig](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/mig/32/30725_2.png) [@mig](https://discourse.mozilla.org/u/mig)\
**Post date:** [December 13, 2017, 10:49pm UTC](https://discourse.mozilla.org/t/window-close-differing-behavior-in-firefox-quantum-versus-previous-versions/23403/4 "2017-12-13T22:49:02Z")

</div>

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:

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

```

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

---

<div class="post-metadata">

**Author:** ![Baptistou](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@Baptistou](https://discourse.mozilla.org/u/Baptistou)\
**Post date:** [December 15, 2017, 10:19pm UTC](https://discourse.mozilla.org/t/window-close-differing-behavior-in-firefox-quantum-versus-previous-versions/23403/5 "2017-12-15T22:19:36Z")

</div>

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);`
