browser.runtime.onInstalled.addListener((ev) => { if (ev.reason == "update") { initialiseSettings(); updateIsSignificant(ev.previousVersion).then( v => { if (v) launchInfoPage(); } ) } else if (ev.reason == "install") { initialiseSettings().then(() => browser.runtime.openOptionsPage()); } }) async function updateIsSignificant(previousVersion) { const significantUpdates = ["0.1.0", "0.2.0", "0.3.0"]; let currentVersion = (await browser.management.getSelf()).version; return (currentVersion in significantUpdates) || currentVersion.endsWith('.0'); // semver! :D } function launchInfoPage(){ browser.tabs.create({url: "/changelog.htm", active: false}) } async function initialiseSettings(){ let defaultSettings = {"enable": true, "showChangelog": true}; const presentSettings = await browser.storage.sync.get(); defaultSettings = Object.fromEntries(Object.entries(defaultSettings).filter((k, v) => !(k in presentSettings))); await browser.storage.sync.set(defaultSettings); }