Best way to get extension version?

1,222 views
Skip to first unread message

Nige

unread,
Mar 21, 2012, 5:13:05 PM3/21/12
to Chromium-extensions
Hi all

What is the best/correct way to get the extension version?

I was using the following, which I found recommended somewhere:

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;

})();

However, this seems to cause an issue in the _generated_background_page_ when using it background,js (with "background": { "scripts": ["background.js"] } in the manifest).

I've changed to the simpler:

var version = chrome.app.getDetails().version;

which seems to work, but I've read that it is (was) buggy?

Cheers,
Nige

Chris Hughes

unread,
Mar 21, 2012, 6:16:35 PM3/21/12
to Nige, Chromium-extensions
var version = chrome.app.getDetails().version;
Works great if you have the sufficient permission, if you are building
something new and dont want to prompt the user for privilege
escallation, then this is the best way to go.

But say you have a published app or extension and need to get the
data... it seems that in that use case XHRing the manifest is the best
option.
-C

> --
> You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
> To post to this group, send email to chromium-...@chromium.org.
> To unsubscribe from this group, send email to chromium-extens...@chromium.org.
> For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.
>

--
sig ver 2.4
twitter: @chews (drunk tweet me)
blog: http://spazout.com
iPhone: 310.933.4533

Devin

unread,
Mar 22, 2012, 1:29:21 PM3/22/12
to Chromium-extensions
Agreed
> > To post to this group, send email to chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to chromium-extensions+unsubscr...@chromium.org.
> > For more options, visit this group athttp://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.
>
> --
> sig ver 2.4
> twitter: @chews(drunk tweet me)

cmrd.Kaash

unread,
Mar 24, 2012, 9:30:41 AM3/24/12
to Chromium-extensions
Hi.
Another way is:

chrome.management.get(chrome.i18n.getMessage("@@extension_id"),
function(extInfo){
// use extInfo.version
});

And you must declare the "management" permission in the extension
manifest to use the management API.
Reply all
Reply to author
Forward
0 new messages