From 7b5dd5c310f7ec4d7f6e329367d34258cce10e8e Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 28 Jun 2020 12:40:02 -0400 Subject: Update browser compatibility and Edge detection (#629) --- ext/mixed/js/core.js | 32 -------------------------------- ext/mixed/js/environment.js | 11 +++++++++-- ext/mixed/js/yomichan.js | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 34 deletions(-) (limited to 'ext/mixed/js') 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 . */ - -/* - * 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 . */ +// 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() { -- cgit v1.2.3