Autoclose window on url change


(Daniele Scasciafratte) #1

I am trying to close a window opened with browser.windows.create the issue is that code is on a browser action file loaded inn an html file. So when that window of the menu is closed the execution is stopped.
I am trying to do a window that when you share a link on a social network the window have to auto close when the url change.
The code is on: https://github.com/Mte90/Share-Backported/blob/master/modal/modal.js#L35

As I can see the only way is with a background script with an interval that getAll the window with something:
browser.windows.getAll({ windowTypes: ["popup"] }).then(logTabsForWindows, onError);
And do something on it when there is the change of the url.

Someone has other ideas?


(Niklas Gollenstede) #2

Why aren’t you listening for tabs.onUpdated or webNavigation.onCommitted from the background page?

You could probably also listen for the 'beforeunload' event with a content script and message the beckground to close the window when that happens. (If the tab navigation is what you want to act on, not “url change”.)


(Daniele Scasciafratte) #3

I wasn’t sure that the windows and tab API are compatible but at the end I used onUpdated and resolved :slight_smile: