How to show notification when chrome extension updates automatically? My requirement is to show a popup after update the chrome extension automatically.
By default, Chrome alerts you whenever a website, app, or extension wants to send you notifications. You can change this setting at any time.
Just visit the web page that you want to monitor, click on the Page Monitor extension icon in Chrome's address bar, and select monitor this page there. That's it. The page is monitored from this point in time on and you will receive notifications whenever it is modified.
Chrome does a good job of updating your extensions automatically, but it checks for updates on its own schedule. If you know that a new version of an extension is out but Chrome hasn't updated it, here's how to do it manually. Start Google Chrome. on the browser toolbar.
There is a chrome.runtime.onInstalled
event you can listen to that fires when the extension is installed or updated (so says the new packaged app documentation), but it's only available in the dev channel right now.
2019 Update: Since this answer was provided in 2012, this event has been moved from the dev to the stable channel.
Here is the complete answer and it is working for me.
//=============== background.js =================
chrome.runtime.onInstalled.addListener(function (details) {
try {
var thisVersion = chrome.runtime.getManifest().version;
if (details.reason == "install") {
console.info("First version installed");
//Send message to popup.html and notify/alert user("Welcome")
} else if (details.reason == "update") {
console.info("Updated version: " + thisVersion);
//Send message to popup.html and notify/alert user
chrome.tabs.query({currentWindow: true, active: true}, function (tabs) {
for( var i = 0; i < tabs.length; i++ ) {
chrome.tabs.sendMessage(tabs[i].id, {name: "showPopupOnUpdated", version: thisVersion});
}
});
}
} catch(e) {
console.info("OnInstall Error - " + e);
}
});
//=============== popup.js =================
//Note: this has to be injected as content script from manifest.json
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
switch (request.name) {
case "showPopupOnUpdated":
alert("Extension got updated to latest version: " + request.version);
break;
}
});
//=============== manifest.js =================
//Note: background.html needs to import background.js
{
"background": {
"page": "background.html"
},
"content_scripts": [
{
"js": [
"js/popup.js"
]
}
]
}
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With