Read the version from manifest.json

Google Chrome-Extension

Google Chrome-Extension Problem Overview


Is there a way for a Chrome extension to read properties from manifest.json? I'd like to be able to read the version number and use it in the extension.

Google Chrome-Extension Solutions


Solution 1 - Google Chrome-Extension

You can just use chrome.runtime.getManifest() to access the manifest data - you don't need to GET it and parse it.

var manifestData = chrome.runtime.getManifest();
console.log(manifestData.version);
console.log(manifestData.default_locale);

Solution 2 - Google Chrome-Extension

The snipet chrome.app.getDetails() is not working anymore, is returning an error:

> TypeError: Object # has no method 'getDetails'

You want to use chrome.runtime.getManifest() instead.

Solution 3 - Google Chrome-Extension

I use this way.

chrome.manifest = (function() {

    var manifestObject = false;
    var xhr = new XMLHttpRequest();

    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4) {
            manifestObject = JSON.parse(xhr.responseText);
        }
    };
    xhr.open("GET", chrome.extension.getURL('/manifest.json'), false);

    try {
        xhr.send();
    } catch(e) {
        console.log('Couldn\'t load manifest.json');
    }

    return manifestObject;

})();

And that's all. This short code snippet loads manifest object and put's it among other chrome.* APIs. So, now you can get any information you want:

// current version 
chrome.manifest.version

// default locale
chrome.manifest.default_locale

Solution 4 - Google Chrome-Extension

Since Chrome 22, you shoud use chrome.runtime

console.log(chrome.runtime.getManifest().version);

Solution 5 - Google Chrome-Extension

It's actually simple.

function yourFunction() {
return chrome.app.getDetails().version;
}

where you can name yourFunction whatever you like.

Then to call it, just insert yourfunction() wherever you want to call the version number.

For example, if your version number is 9.07, then yourfunction() actually equals the numeric value of 9.07

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBen McCannView Question on Stackoverflow
Solution 1 - Google Chrome-ExtensionnfmView Answer on Stackoverflow
Solution 2 - Google Chrome-ExtensionOndrejView Answer on Stackoverflow
Solution 3 - Google Chrome-ExtensionBenoitParisView Answer on Stackoverflow
Solution 4 - Google Chrome-ExtensiontardypView Answer on Stackoverflow
Solution 5 - Google Chrome-Extensionuser2651403View Answer on Stackoverflow