UPDATE As pointed out by commenter Andreas, you can now use a simpler way:
chrome.runtime.getManifest().version
The code below no longer is necessary but kept as reference.
Following on from yesterday’s post about getting the version number of your own firefox extension, what if you were now developing a Google Chrome extension and want the same thing? Google Chrome’s extension API is much more limited that Firefox’s. There’s no explicit extension-metadata-getting API that I know of. However, we do know that the version information is tucked away in manifest.json. With this knowledge and coupled with a few friendly APIs (XMLHttpRequest & JSON.parse) we can now have the equivalent function for chrome:
[js]
function getVersion(callback) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open(‘GET’, ‘manifest.json’);
xmlhttp.onload = function (e) {
var manifest = JSON.parse(xmlhttp.responseText);
callback(manifest.version);
}
xmlhttp.send(null);
}
// to use
var version;
getVersion(function (ver) { version = ver; });
// version is populated after an indeterminate amount of time
[/js]
As XMLHttpRequest is asynchronous, our method needs a callback to receive the version information. You can also get whatever other information you want in your mainfest.json. So there you go.
Pingback: Getting the version number of your own Chrome Extension | Eli Thompson's Blog
Cheers for that, just looking into this, and was going the route of using the chrome.management API to iterate over the installed extensions, but your method does exactly what I want without yet another permission.
Thanks for that.
Just say that it seems there is a function (perhaps undocumented) to do this.
chrome.app.getDetails().version
Works for me (I’m running v22)
Saw it here:
https://groups.google.com/a/chromium.org/forum/?fromgroups=#!topic/chromium-extensions/F-eg1H6aY5k
I’ve just found a very simple *and* documented way:
chrome.runtime.getManifest().version
You basically can access anything in the manifest this way.