BrowserDetect gets browser from env. Package.json updated to provide BROWSER in env
This commit is contained in:
parent
8f4c201bb1
commit
47b1bc68e0
18
package.json
18
package.json
@ -4,19 +4,27 @@
|
||||
"description": "Ultrawidify but with vue settings and popup",
|
||||
"author": "Tamius Han <tamius.han@gmail.com>",
|
||||
"scripts": {
|
||||
"build": "cross-env NODE_ENV=production webpack --hide-modules",
|
||||
"build:dev": "cross-env NODE_ENV=development webpack --hide-modules",
|
||||
"build": "cross-env NODE_ENV=production BROWSER=firefox webpack --hide-modules",
|
||||
"build-chrome": "cross-env NODE_ENV=production BROWSER=chrome webpack --hide-modules",
|
||||
"build-edge": "cross-env NODE_ENV=production BROWSER=edge webpack --hide-modules",
|
||||
"build:dev": "cross-env NODE_ENV=development BROWSER=firefox webpack --hide-modules",
|
||||
"build-chrome:dev": "cross-env NODE_ENV=development BROWSER=chrome webpack --hide-modules",
|
||||
"build-edge:dev": "cross-env NODE_ENV=development BROWSER=edge webpack --hide-modules",
|
||||
"build-zip": "node scripts/build-zip.js",
|
||||
"watch": "npm run build -- --watch",
|
||||
"watch:dev": "cross-env HMR=true npm run build:dev -- --watch"
|
||||
"watch-chrome": "npm run build-chrome-- --watch",
|
||||
"watch-edge": "npm run build-edge -- --watch",
|
||||
"watch:dev": "cross-env HMR=true npm run build:dev -- --watch",
|
||||
"watch-chrome:dev": "cross-env HMR=true npm run build-chrome:dev -- --watch",
|
||||
"watch-edge:dev": "cross-env HMR=true npm run build-edge:dev -- --watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/core-js": "^2.5.0",
|
||||
"@types/es6-promise": "^3.3.0",
|
||||
"fs-extra": "^7.0.1",
|
||||
"vue": "^2.5.17",
|
||||
"vuex": "^3.0.1",
|
||||
"vuex-webextensions": "^1.2.6",
|
||||
"webextension-polyfill": "^0.3.1"
|
||||
"vuex-webextensions": "^1.2.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.1.2",
|
||||
|
@ -1,71 +1,13 @@
|
||||
import Debug from '../conf/Debug';
|
||||
import Debug from './Debug.js';
|
||||
|
||||
var _bd_usebrowser = "firefox";
|
||||
var _bd_isFirefox = true;
|
||||
var _bd_isChrome = false;
|
||||
var _bd_isEdge = false; // we'll see if FF
|
||||
const BrowserDetect = {
|
||||
firefox: process.env.BROWSER === 'firefox',
|
||||
chrome: process.env.BROWSER === 'chrome',
|
||||
edge: process.env.BROWSER === 'edge',
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
// 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.
|
||||
|
||||
// if (Browser.name.toLowerCase().indexOf(firefox) !== -1 || Browser.vendor.toLowerCase().indexOf(mozilla) !== -1) {
|
||||
_bd_isFirefox = true;
|
||||
_bd_isEdge = false;
|
||||
// }
|
||||
|
||||
}
|
||||
catch (e) {
|
||||
if(Debug.debug) {
|
||||
console.info("[BrowserDetect] browser.runtime.getBrowserInfo() probably failed. This means we're probably not using firefox.", e)
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
if (Debug.debug) {
|
||||
console.log("Loading: BrowserDetect.js\n\nprocess.env.BROWSER:", process.env.BROWSER, "Exporting BrowserDetect:", BrowserDetect);
|
||||
}
|
||||
|
||||
export default BrowserDetect;
|
Loading…
Reference in New Issue
Block a user