Read the Safari extension version from the extension code itself

I would like to report the used extended version for maintenance. Is there any way to read the extension version number inside the extension?

+5
source share
3 answers

You can access the version using the displayVersionclass property SafariExtension.

console.log(safari.extension.displayVersion);
// => "1.0"

API Documentation

+7
source

You can do XMLHttpRequest safari.extension.baseURI + "Info.plist"and get the version from there, although it's a bit complicated.

+2
source

Further, @cprcrack's answer, if you use jQuery in your extension and you are targeting Safari 5, you can get the version number as follows:

jQuery.get(safari.extension.baseURI + 'Info.plist', function(data){
    $('dict > key', data).each(function(){
        if ($(this).text() == 'CFBundleShortVersionString') {
            var versionNumber = $(this).next().text();
            // Do something with versionNumber here
        }
    });
});
+1
source

All Articles