2018-12-30 23:16:09 +01:00
|
|
|
import Debug from '../conf/Debug';
|
|
|
|
|
|
|
|
var _bd_usebrowser = "firefox";
|
|
|
|
var _bd_isFirefox = true;
|
|
|
|
var _bd_isChrome = false;
|
|
|
|
var _bd_isEdge = false; // we'll see if FF
|
|
|
|
|
2018-12-31 01:03:07 +01:00
|
|
|
try{
|
|
|
|
// todo: find something that works in firefox but not in edge (or vice-versa)
|
|
|
|
// note that this function returns a promise! and is broken for some reason
|
|
|
|
var browserinfo = browser.runtime.getBrowserInfo();
|
2018-12-30 23:16:09 +01:00
|
|
|
|
2018-12-31 01:03:07 +01:00
|
|
|
// we don't need to actually check because only firefox supports that.
|
|
|
|
// if we're not on firefox, the above call will probably throw an exception anyway.
|
|
|
|
// if browsers other than firefox start supporting that, well ... we'll also need to actually await for promise
|
|
|
|
// that getBrowserInfo() returns to resolve.
|
2018-12-30 23:16:09 +01:00
|
|
|
|
2018-12-31 01:03:07 +01:00
|
|
|
// if (Browser.name.toLowerCase().indexOf(firefox) !== -1 || Browser.vendor.toLowerCase().indexOf(mozilla) !== -1) {
|
|
|
|
_bd_isFirefox = true;
|
|
|
|
_bd_isEdge = false;
|
|
|
|
// }
|
2018-12-30 23:16:09 +01:00
|
|
|
|
2018-12-31 01:03:07 +01:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
if(Debug.debug) {
|
|
|
|
console.info("[BrowserDetect] browser.runtime.getBrowserInfo() probably failed. This means we're probably not using firefox.", e)
|
|
|
|
}
|
|
|
|
};
|
2018-12-30 23:16:09 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
if(browser === undefined){ // This is a good sign we're in chrome or chromium-based browsers
|
|
|
|
if(chrome){
|
|
|
|
browser = chrome;
|
|
|
|
_bd_usebrowser = "chrome";
|
|
|
|
_bd_isChrome = true;
|
|
|
|
_bd_isEdge = false;
|
|
|
|
_bd_isFirefox = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.log("e=",e);
|
|
|
|
if(chrome){
|
|
|
|
// browser = chrome;
|
|
|
|
_bd_usebrowser = "chrome";
|
|
|
|
_bd_isChrome = true;
|
|
|
|
_bd_isEdge = false;
|
|
|
|
_bd_isFirefox = false;
|
|
|
|
} else {
|
|
|
|
console.log("No chrome either.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("extension didn't crash after browser === undefined failed");
|
|
|
|
|
|
|
|
var BrowserDetect = {
|
|
|
|
usebrowser: _bd_usebrowser,
|
|
|
|
firefox: _bd_isFirefox,
|
|
|
|
chrome: _bd_isChrome,
|
|
|
|
edge: _bd_isEdge
|
|
|
|
}
|
|
|
|
|
|
|
|
if(Debug.debug){
|
|
|
|
console.log("BrowserDetect loaded! Here's BrowserDetect object:", BrowserDetect)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (BrowserDetect.firefox) {
|
|
|
|
// browser = window.browser;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default BrowserDetect;
|