Skip to content

Instantly share code, notes, and snippets.

@NiklasGollenstede
Last active October 16, 2019 16:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NiklasGollenstede/5507687123e4088f70ea1337af004848 to your computer and use it in GitHub Desktop.
Save NiklasGollenstede/5507687123e4088f70ea1337af004848 to your computer and use it in GitHub Desktop.
Manually trigger the update of Firefox extensions
'use strict'; /* globals AddonManager, */
/**
* Triggers the update of an extension in Firefox (version 60).
* Paste the function in the Browser console (Ctrl+Shift+J),
* call it with an extension ID and watch the console output.
*
* I wrote this to test the automatic build and update of my
* extensions `-dev` channel, see:
* - https://gist.github.com/NiklasGollenstede/87664c7f2822b15f86362388270a16a8
* - https://gist.github.com/NiklasGollenstede/60aa2dc957f985eff2b7a2655ea1092b
*
* This is pieced together from noLegacyStartupCheck > checkOne in
* resource://gre/modules/addons/XPIProvider.jsm of Firefox 60.
* It looks like this should still work in Firefox 70.
* It might not be wise to use this with a production profile.
*
* @param {string} id The "Extension ID" on `about:debugging#addons`.
*/
async function updateNow(id) {
const addon = (await AddonManager.getAddonByID(id));
const update = (await new Promise(resolve => addon.findUpdates({
onUpdateFinished() { resolve(null); },
onUpdateAvailable(addon, update) { resolve(update); },
}, AddonManager.UPDATE_WHEN_NEW_APP_INSTALLED))); // use UPDATE_WHEN_USER_REQUESTED instead?
if (!update) { console.log('no update available'); return; }
console.log('installing ...');
try { (await new Promise((good, bad) => { update.addListener({
onDownloadFailed: bad, onInstallFailed: bad, onInstallEnded: good,
}); update.install(); })); }
catch (error) { console.error('installation failed', error); return; }
console.log('installation done');
}
void updateNow;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment