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",
|
"description": "Ultrawidify but with vue settings and popup",
|
||||||
"author": "Tamius Han <tamius.han@gmail.com>",
|
"author": "Tamius Han <tamius.han@gmail.com>",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "cross-env NODE_ENV=production webpack --hide-modules",
|
"build": "cross-env NODE_ENV=production BROWSER=firefox webpack --hide-modules",
|
||||||
"build:dev": "cross-env NODE_ENV=development 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",
|
"build-zip": "node scripts/build-zip.js",
|
||||||
"watch": "npm run build -- --watch",
|
"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": {
|
"dependencies": {
|
||||||
"@types/core-js": "^2.5.0",
|
"@types/core-js": "^2.5.0",
|
||||||
"@types/es6-promise": "^3.3.0",
|
"@types/es6-promise": "^3.3.0",
|
||||||
|
"fs-extra": "^7.0.1",
|
||||||
"vue": "^2.5.17",
|
"vue": "^2.5.17",
|
||||||
"vuex": "^3.0.1",
|
"vuex": "^3.0.1",
|
||||||
"vuex-webextensions": "^1.2.6",
|
"vuex-webextensions": "^1.2.6"
|
||||||
"webextension-polyfill": "^0.3.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.1.2",
|
"@babel/core": "^7.1.2",
|
||||||
|
@ -1,71 +1,13 @@
|
|||||||
import Debug from '../conf/Debug';
|
import Debug from './Debug.js';
|
||||||
|
|
||||||
var _bd_usebrowser = "firefox";
|
const BrowserDetect = {
|
||||||
var _bd_isFirefox = true;
|
firefox: process.env.BROWSER === 'firefox',
|
||||||
var _bd_isChrome = false;
|
chrome: process.env.BROWSER === 'chrome',
|
||||||
var _bd_isEdge = false; // we'll see if FF
|
edge: process.env.BROWSER === 'edge',
|
||||||
|
}
|
||||||
|
|
||||||
try{
|
if (Debug.debug) {
|
||||||
// todo: find something that works in firefox but not in edge (or vice-versa)
|
console.log("Loading: BrowserDetect.js\n\nprocess.env.BROWSER:", process.env.BROWSER, "Exporting BrowserDetect:", BrowserDetect);
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default BrowserDetect;
|
export default BrowserDetect;
|
Loading…
Reference in New Issue
Block a user