Path: blob/main/files/en-us/mozilla/add-ons/webextensions/api/sessions/onchanged/index.md
6563 views
------{{AddonSidebar()}}
Fired whenever the list of closed tabs or windows changes.
Syntax
Events have three functions:
addListener(callback): Adds a listener to this event.
removeListener(listener): Stop listening to this event. The
listenerargument is the listener to remove.
hasListener(listener): Check whether
listeneris registered for this event. Returnstrueif it is listening,falseotherwise.
addListener syntax
Parameters
callback: Function that will be called when this event occurs. It's passed no parameters.
Browser compatibility
{{Compat}}
Examples
This very annoying extension listens for onChanged, then immediately restores the most recently closed session, thus making it impossible to close windows or tabs:
{{WebExtExamples}}
Note: This API is based on Chromium's
chrome.sessionsAPI.