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

I know there is the 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.

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

This was too simple. :laughing:

1 Like

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 :slight_smile:

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.

Ah thanks, indeed, I did not think about that… I’ve noted it.

BTW, added it to the Stackoverflow answer.

1 Like