summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-06-28 12:40:02 -0400
committerGitHub <noreply@github.com>2020-06-28 12:40:02 -0400
commit7b5dd5c310f7ec4d7f6e329367d34258cce10e8e (patch)
tree00151155ea5f3dc438c9230e485a72613a41d00f
parentcdf191336aa616a206b977ba3beeb1233cf41c32 (diff)
Update browser compatibility and Edge detection (#629)
-rw-r--r--.eslintrc.json11
-rw-r--r--ext/bg/css/settings.css2
-rw-r--r--ext/mixed/js/core.js32
-rw-r--r--ext/mixed/js/environment.js11
-rw-r--r--ext/mixed/js/yomichan.js19
5 files changed, 38 insertions, 37 deletions
diff --git a/.eslintrc.json b/.eslintrc.json
index b7ed0164..018e23b4 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -83,6 +83,12 @@
},
"overrides": [
{
+ "files": ["ext/mixed/js/core.js"],
+ "env": {
+ "webextensions": false
+ }
+ },
+ {
"files": ["ext/**/*.js"],
"excludedFiles": ["ext/mixed/js/core.js"],
"globals": {
@@ -101,8 +107,7 @@
"deferPromise": "readonly",
"clone": "readonly",
"EventDispatcher": "readonly",
- "EventListenerCollection": "readonly",
- "EXTENSION_IS_BROWSER_EDGE": "readonly"
+ "EventListenerCollection": "readonly"
}
},
{
@@ -116,7 +121,7 @@
}
},
{
- "files": ["ext/mixed/js/core.js"],
+ "files": ["ext/mixed/js/yomichan.js"],
"globals": {
"chrome": "writable"
}
diff --git a/ext/bg/css/settings.css b/ext/bg/css/settings.css
index 7659f6f2..1b945310 100644
--- a/ext/bg/css/settings.css
+++ b/ext/bg/css/settings.css
@@ -208,6 +208,7 @@ input[type=checkbox].storage-button-checkbox {
}
html:root[data-browser=edge] [data-show-for-browser~=edge],
+html:root[data-browser=edge-legacy] [data-show-for-browser~=edge-legacy],
html:root[data-browser=chrome] [data-show-for-browser~=chrome],
html:root[data-browser=firefox] [data-show-for-browser~=firefox],
html:root[data-browser=firefox-mobile] [data-show-for-browser~=firefox-mobile],
@@ -221,6 +222,7 @@ html:root[data-operating-system=openbsd] [data-show-for-operating-system~=openbs
}
html:root[data-browser=edge] [data-hide-for-browser~=edge],
+html:root[data-browser=edge-legacy] [data-hide-for-browser~=edge-legacy],
html:root[data-browser=chrome] [data-hide-for-browser~=chrome],
html:root[data-browser=firefox] [data-hide-for-browser~=firefox],
html:root[data-browser=firefox-mobile] [data-hide-for-browser~=firefox-mobile],
diff --git a/ext/mixed/js/core.js b/ext/mixed/js/core.js
index 9b3ea3e2..e22be33d 100644
--- a/ext/mixed/js/core.js
+++ b/ext/mixed/js/core.js
@@ -15,38 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-
-/*
- * Extension information
- */
-
-function _extensionHasChrome() {
- try {
- return typeof chrome === 'object' && chrome !== null;
- } catch (e) {
- return false;
- }
-}
-
-function _extensionHasBrowser() {
- try {
- return typeof browser === 'object' && browser !== null;
- } catch (e) {
- return false;
- }
-}
-
-const EXTENSION_IS_BROWSER_EDGE = (
- _extensionHasBrowser() &&
- (!_extensionHasChrome() || (typeof chrome.runtime === 'undefined' && typeof browser.runtime !== 'undefined'))
-);
-
-if (EXTENSION_IS_BROWSER_EDGE) {
- // Edge does not have chrome defined.
- chrome = browser;
-}
-
-
/*
* Error handling
*/
diff --git a/ext/mixed/js/environment.js b/ext/mixed/js/environment.js
index 5bd84010..1f4038d2 100644
--- a/ext/mixed/js/environment.js
+++ b/ext/mixed/js/environment.js
@@ -67,8 +67,15 @@ class Environment {
}
async _getBrowser() {
- if (EXTENSION_IS_BROWSER_EDGE) {
- return 'edge';
+ try {
+ if (chrome.runtime.getURL('/').startsWith('ms-browser-extension://')) {
+ return 'edge-legacy';
+ }
+ if (/\bEdge?\//.test(navigator.userAgent)) {
+ return 'edge';
+ }
+ } catch (e) {
+ // NOP
}
if (typeof browser !== 'undefined') {
try {
diff --git a/ext/mixed/js/yomichan.js b/ext/mixed/js/yomichan.js
index 5fa504ef..ab1afcd9 100644
--- a/ext/mixed/js/yomichan.js
+++ b/ext/mixed/js/yomichan.js
@@ -15,6 +15,25 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+// Set up chrome alias if it's not available (Edge Legacy)
+if ((() => {
+ let hasChrome = false;
+ let hasBrowser = false;
+ try {
+ hasChrome = (typeof chrome === 'object' && chrome !== null && typeof chrome.runtime !== 'undefined');
+ } catch (e) {
+ // NOP
+ }
+ try {
+ hasBrowser = (typeof browser === 'object' && browser !== null && typeof browser.runtime !== 'undefined');
+ } catch (e) {
+ // NOP
+ }
+ return (hasBrowser && !hasChrome);
+})()) {
+ chrome = browser;
+}
+
const yomichan = (() => {
class Yomichan extends EventDispatcher {
constructor() {