Proposal: runtime.onSessionStart event.
polywock opened this issue · comments
If an extension needs to initialize by moving some storage items from local storage into session storage. There's no single event that can be used to do that.
You would have to use both onInstalled and onStartup. This has a few issues.
- It can run multiple times. So you need to set some flag on session storage to ensure you're not initializing multiple times.
- It's unclear if this approach handles 100% of scenarios as the docs don't mention it.
Proposal
browser.runtime.onSessionStart
event that is fired when the extension's session starts.
browser.runtime.onSessionStart.addListener(() => {
// good place to initialize API labeled 'A' from the memo linked below.
})
Relevant memo.
https://github.com/w3c/webextensions/blob/main/memo/persistence-of-states.md#definitions
This proposal can supersede #353 (runtime.onEnabled) and the existing runtime.onInstalled if this event receives their params (reason, previousVersion, etc.) with "enabled"
added to the enum of reasons.
This proposal is the same as proposal #353 just with a different name. runtime.onSessionStart
, runtime.onExtensionStartup
or runtime.onExtensionLoaded
are the same thing just different names. Chrome is supportive of both this event and onEnabled
#353 (comment) , other browsers are supportive too.
Great, that's exactly it.