Reputation: 2966
I have an extension and I did lots of refactoring in my code, I want to publish a new version but in my new code I want to detect when the extension is being updated and do some actions.
I know that with chrome.management I can detect other extension update but I want to detect my own extension update.
Upvotes: 3
Views: 1068
Reputation: 22834
You don't need management permission to do that.
You can use chrome.app.getDetails().version
To get the last version of your extension using your background page. Than you can store it in localStorage. Every time you load your background page or once every hour you can check if the version matches the one you have on localStorage and detect new installs or updates.
I wonder if there's a better/easier way to do it. But right now this is what I do.
EDIT:
Alternatively you can use this code to get the latest version:
var url = chrome.extension.getURL("manifest.json");
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(e) {
if(xhr.readyState == 2 && xhr.status == 200) {
var manifest = JSON.parse(xhr.responseText);
alert("Version: " + manifest.version);
}
};
xhr.open("GET", url);
xhr.send();
extracted from this other SO response.
Upvotes: 3