Skip to content

Latest commit

 

History

History
38 lines (25 loc) · 1.26 KB

on-extension-start.md

File metadata and controls

38 lines (25 loc) · 1.26 KB

onExtensionStart

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);

Compatibility

  • Chrome: 112+ (no MV2 Event Pages support)
  • Safari: 16.4
  • Firefox: 115

Permissions

Context

  • background worker
  • background page
  • event page (not in Chrome)