(Firefox) WebExtension 如何知道它自己的版本?
How can a (Firefox) WebExtension know its own version?
我正在将旧版 Firefox 扩展移植到 WebExtensions。我想在 运行 时间知道扩展本身的版本号。现在我在做:
let extensionVersion = (function() {
var xhr = new XMLHttpRequest();
xhr.overrideMimeType('application/json');
xhr.open('GET', browser.extension.getURL('manifest.json'), false);
xhr.send(null);
var manifest = JSON.parse(xhr.responseText);
return manifest.version;
})();
这个依赖于同步 XHR 的肮脏 hack。有没有更好的方法?
有一个专门用于检索清单的函数:
browser.runtime.getManifest().version
https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/runtime/getManifest
我正在将旧版 Firefox 扩展移植到 WebExtensions。我想在 运行 时间知道扩展本身的版本号。现在我在做:
let extensionVersion = (function() {
var xhr = new XMLHttpRequest();
xhr.overrideMimeType('application/json');
xhr.open('GET', browser.extension.getURL('manifest.json'), false);
xhr.send(null);
var manifest = JSON.parse(xhr.responseText);
return manifest.version;
})();
这个依赖于同步 XHR 的肮脏 hack。有没有更好的方法?
有一个专门用于检索清单的函数:
browser.runtime.getManifest().version
https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/runtime/getManifest