How do I link to version information in a Google Chrome extension?

I use

chrome.tabs.create({url:"URL here"}) 

to open a new tab in my LRG. To this URL I want to add the extension version number specified in the manifest.json file:

 "version": "1.2", 

How can I access the version number in javascript while creating a new tab?

+4
source share
3 answers

You can get your own manifest and version using the following:

 var url = chrome.extension.getURL("manifest.json"); var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function(e) { if(xhr.readyState == 2 && xhr.status == 200) { var manifest = JSON.parse(xhr.responseText); alert("Version: " + manifest.version); } }; xhr.open("GET", url); xhr.send(); 

Once you have the version number, you can make your own tabs, which you need to do.

+4
source

Try in your extension:

 chrome.app.getDetails().version 

I don’t know why it is not among other APIs , but it works in my Chrome 13 beta strong>. Check it out sooner in earlier versions of Chrome :).

EDIT: It is probably a little buggy.

+7
source

I don't have enough comments for comments, but regarding the Kinlan XMLHttpRequest answer:

I found this very useful, but I noticed that it should wait for readyState == 4 (not 2).

It worked great for me and it looks like it should be reliable.

0
source

All Articles