Mordred
Mordred

Reputation: 3941

Specify a custom key in Chrome Extension manifest?

I've got a chrome extension that I update frequently, and so I wrote an update notification popup for it. It displays when the manifest.version changes so that the user doesn't miss that there was an update with new options that they'd need to enable/disable. Then I realized that for minor big fixes and the like, it doesn't make sense to bug the user. Because I have to update the manifest version everytime I update the script, I thought it would be nice to just have an 'new_options' : true field in the manifest that my script could key off of. Unfortunately when I tried it I get this:

enter image description here

Is there some way to add your own custom key/value entries in the chrome manifest?

I checked the documentation and it doesn't appear that there are any "free JSON" enabled keys, but I thought I'd ask before completely giving up on the idea. I could easily put a global flag in the script itself, but I know me, and I'm liable to forget to change it every update.

Upvotes: 2

Views: 2211

Answers (1)

Rob W
Rob W

Reputation: 349042

Although the "Unrecognised manifest key 'new_options'" warning can safely be ignored, I recommend to not abuse this method for toggling features. An extension cannot change its manifest file, so having a hypothetical "new_options": true field would not be very useful.

A better way to manage notifications for updates is to consistently stick to the following convention and use chrome.runtime.onInstalled:

  1. Use the <major>.<minor> version numbering.
  2. For minor changes, increase <minor>.
  3. For major changes requiring (popup/changelog) notifications, increase <major>.

For example:

chrome.runtime.onInstalled.addListener(function(details) {
    if (details.reason == 'install') {
        // First-run code here.
        // TODO: Thank the user for installing the extension
    } else if (details.reason == 'update') {
        // Check for update
        var versionPartsOld = details.previousVersion.split('.');
        var versionPartsNew = chrome.runtime.getManifest().version.split('.');
        if (versionPartsOld[0] != versionPartsNew[0]) {
            // Major version change!
            // TODO: Show changelog for update?
        }
    }
});

Upvotes: 5

Related Questions