Last active
October 16, 2019 16:34
-
-
Save NiklasGollenstede/5507687123e4088f70ea1337af004848 to your computer and use it in GitHub Desktop.
Manually trigger the update of Firefox extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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