Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: runtime.onSessionStart event. #509

Closed
polywock opened this issue Dec 16, 2023 · 3 comments
Closed

Proposal: runtime.onSessionStart event. #509

polywock opened this issue Dec 16, 2023 · 3 comments
Labels
status: duplicate Duplicate issue

Comments

@polywock
Copy link

polywock commented Dec 16, 2023

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.

  1. It can run multiple times. So you need to set some flag on session storage to ensure you're not initializing multiple times.
  2. 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

@tophf
Copy link

tophf commented Dec 17, 2023

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.

@hanguokai
Copy link
Member

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.

@hanguokai hanguokai added status: duplicate Duplicate issue and removed needs-triage labels Dec 17, 2023
@polywock
Copy link
Author

Great, that's exactly it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate Duplicate issue
Projects
None yet
Development

No branches or pull requests

3 participants