Not to be confused with chrome.runtime.onStartup
, this event is actually called when the extension starts. The native onStartup
is not fired when the user manually disables and re-enables the extension.
In event pages and service workers, the background file is loaded and unloaded automatically; This event will ensure that the specified listener is only ever run once per "extension start."
Warning Chrome has serious issues around the background service worker so this might not work well for everyone.
import {onExtensionStart} from 'webext-events';
async function listener() {
console.log('Extension started now');
await chrome.storage.local.set({started: Date.now()})
}
// Add the listener as soon as possible or else they'll miss the "onExtensionStart" event
onExtensionStart.addListener(listener);
- Chrome: 112+ (no MV2 Event Pages support)
- Safari: 16.4
- Firefox: 115
storage
(due tochrome.storage.session
usage)
- background worker
- background page
- event page (not in Chrome)