Index: templates/geckoInfo.js.tmpl |
=================================================================== |
--- a/templates/geckoInfo.js.tmpl |
+++ b/templates/geckoInfo.js.tmpl |
@@ -12,13 +12,33 @@ |
exports.platform = "gecko"; |
exports.platformVersion = "0"; |
let match = /\brv:(\d+(?:\.\d+)?)\b/.exec(navigator.userAgent); |
if (match) |
exports.platformVersion = match[1]; |
-browser.runtime.getBrowserInfo().then(browserInfo => |
+let exportApplicationInfo = info => |
+{ |
+ exports.application = info.name.toLowerCase(); |
+ exports.applicationVersion = info.version; |
+}; |
+ |
+// Firefox 50 does not support runtime.getBrowserInfo |
+if ("getBrowserInfo" in browser.runtime) |
+{ |
+ browser.runtime.getBrowserInfo().then(exportApplicationInfo); |
+} |
+else |
{ |
- exports.application = browserInfo.name.toLowerCase(); |
- exports.applicationVersion = browserInfo.version; |
-}); |
+ // Based on the Firefox UA string reference: |
+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox |
+ // The regular expression here will capture the "appname/appversion" part of |
+ // "Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail |
+ // Firefox/firefoxversion appname/appversion" if present, otherwise it'll |
+ // capture "Firefox/firefoxversion" |
+ let browserInfo = |
+ /\brv:(?:\d+(?:\.\d+)?)\) [^\/]+\/[^ ]+(?: ([^\/]+)\/([^ ]+))+\b/ |
+ .exec(navigator.userAgent); |
+ if (browserInfo) |
+ exportApplicationInfo({name: browserInfo[1], version: browserInfo[2]}); |
Sebastian Noack
2017/09/13 17:38:01
There is only one application this code is possibl
Manish Jethani
2017/09/14 04:27:11
Hypothetically, suppose other Gecko-based browsers
Sebastian Noack
2017/09/14 04:33:41
This would only be relevant in the unlikely case t
Manish Jethani
2017/09/14 06:06:50
Done.
|
+} |