Read the version from manifest.json
Since Chrome 22, you shoud use chrome.runtime
console.log(chrome.runtime.getManifest().version);
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
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);
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.