Yevgeniy
Yevgeniy

Reputation: 1333

chrome.app.getDetails() returns null

I was trying to get the version of my extension at run-time using chrome.app.getDetails().version and noticed that chrome.app.getDetails() returns null. Surprisingly, there is no talk about this in the online community and the function isn't even documented by the Google folks. Is there a permission I am missing? I do have tabs enabled.

Upvotes: 0

Views: 2197

Answers (3)

gmo
gmo

Reputation: 9000

Very old... I know
But in case if someone is looking for this, you can have your extension version reading the manifest file with chrome.runtime API and the getManifest Method.

Ex. in your background script:

var manifest = chrome.runtime.getManifest();
var current_version = manifest.version;

console.info('Current Version: ', current_version);

The object returned is a serialization of the full manifest file, so you can get all the info in the manifest file

So.. if you want for example all and only the matches of your content_scripts... for say something...

for(var i in manifest.content_scripts) {
  console.log(manifest.content_scripts[i]['matches']));
}

Note: Stable since Chrome 22

Upvotes: 4

TheRealJAG
TheRealJAG

Reputation: 2088

Here is what I'm using to pull the current version.

    var manifest = new XMLHttpRequest();
    manifest.open("get", "/manifest.json", true);
    manifest.onreadystatechange = function (e) { if (manifest.readyState == 4) {console.log(JSON.parse(manifest.responseText).version)} };
    manifest.send({}); 

Upvotes: 0

int3
int3

Reputation: 13201

It's undocumented because they might be moving getDetails to a different part of the API -- see this bug. It's currently working on my copy of Chrome (beta channel), but I wouldn't be surprised if they've disabled it in a newer release. In the meantime you can just do an AJAX query to get the manifest.json of your extension -- you can get its URI using chrome.extension.getURL("manifest.json").

Upvotes: 2

Related Questions