# Can an extension close it's own popup opened by a browserAction or pageAction?

**URL:** <https://discourse.mozilla.org/t/can-an-extension-close-its-own-popup-opened-by-a-browseraction-or-pageaction/38645>\
**Category:** Development\
**Created:** [April 25, 2019, 1:23pm UTC](https://discourse.mozilla.org/t/can-an-extension-close-its-own-popup-opened-by-a-browseraction-or-pageaction/38645 "2019-04-25T13:23:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rugkx](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/rugkx/32/19322_2.png) [@rugkx](https://discourse.mozilla.org/u/rugkx)\
**Post date:** [April 25, 2019, 1:23pm UTC](https://discourse.mozilla.org/t/can-an-extension-close-its-own-popup-opened-by-a-browseraction-or-pageaction/38645/1 "2019-04-25T13:23:38Z")

</div>

I know there is the [`openPopup`](https://developer.mozilla.org/docs/Mozilla/Add-ons/WebExtensions/API/browserAction/openPopup) API to open a browserAction popup.

However, when it is open and a user e.g. selected something, can I somehow close it?

The same applies for a pageAction.

* * *

Cross-posted [at Stackoverflow](https://stackoverflow.com/q/55850301/5008962).

---

<div class="post-metadata">

**Author:** ![rugkx](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/rugkx/32/19322_2.png) [@rugkx](https://discourse.mozilla.org/u/rugkx)\
**Post date:** [April 25, 2019, 1:38pm UTC](https://discourse.mozilla.org/t/can-an-extension-close-its-own-popup-opened-by-a-browseraction-or-pageaction/38645/2 "2019-04-25T13:38:35Z")

</div>

Actually, as for any other website a simple `window.close();` works totally fine!

This was too simple. 😆

---

<div class="post-metadata">

**Author:** ![juraj.masiar](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/juraj.masiar/32/30587_2.png) [@juraj.masiar](https://discourse.mozilla.org/u/juraj.masiar)\
**Post date:** [April 25, 2019, 7:01pm UTC](https://discourse.mozilla.org/t/can-an-extension-close-its-own-popup-opened-by-a-browseraction-or-pageaction/38645/3 "2019-04-25T19:01:30Z")

</div>

Actually it’s not that simple once you try to port your code for Firefox for Android. In there, pop-ups are tabs and `window.close()` will suddenly not work anymore 🙂

You will have to use `browser.tabs.getCurrent().then(tab => browser.tabs.remove(tab.id))`. Plus you need to detect that you are running Android using `browser.runtime.getPlatformInfo()` function.

But I have to say, that porting my several thousands lines of code for Android was pretty quick as the API is almost all there. So if it makes sense for your add-on, I would encourage you to add Android support.

---

<div class="post-metadata">

**Author:** ![rugkx](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/rugkx/32/19322_2.png) [@rugkx](https://discourse.mozilla.org/u/rugkx)\
**Post date:** [April 25, 2019, 7:15pm UTC](https://discourse.mozilla.org/t/can-an-extension-close-its-own-popup-opened-by-a-browseraction-or-pageaction/38645/4 "2019-04-25T19:15:16Z")

</div>

Ah thanks, indeed, I did not think about that… [I’ve noted it](https://github.com/rugk/awesome-emoji-picker/issues/22).

BTW, added it [to the Stackoverflow answer](https://stackoverflow.com/posts/55850630/revisions).
