Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome extension update notification

How to show notification when chrome extension updates automatically? My requirement is to show a popup after update the chrome extension automatically.

like image 273
KKSB Avatar asked Jul 19 '12 06:07

KKSB


People also ask

Can Chrome extensions send notifications?

By default, Chrome alerts you whenever a website, app, or extension wants to send you notifications. You can change this setting at any time.

How do I get Chrome to notify me when a website is updated?

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.

Do Chrome extensions get update automatically?

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.


2 Answers

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.

like image 189
gengkev Avatar answered Oct 11 '22 10:10

gengkev


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.

like image 23
Veeresh Devireddy Avatar answered Oct 11 '22 11:10

Veeresh Devireddy