Detect Chrome extension first run / update
google-chrome, google-chrome-extension
Solution
In newer versions of Chrome (since Chrome 22), you can use the `chrome.runtime.onInstalled` event, which is much cleaner.
Example:
// Check whether new version is installed
chrome.runtime.onInstalled.addListener(function(details){
if(details.reason == "install"){
console.log("This is a first install!");
}else if(details.reason == "update"){
var thisVersion = chrome.runtime.getManifest().version;
console.log("Updated from " + details.previousVersion + " to " + thisVersion + "!");
}
});
Problem
How can an extension find out that it is being run for the first time or has just been updated, so that the extension can perform some specific actions? (e.g. open a help page or update settings)