diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 492d5f823..c3c35c8bb 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -39,10 +39,21 @@ vAPI.chromiumVersion = (function(){ var matches = /\bChrom(?:e|ium)\/(\d+)\b/.exec(navigator.userAgent); return matches !== null ? parseInt(matches[1], 10) : NaN; })(); + vAPI.cantWebsocket = chrome.webRequest.ResourceType instanceof Object === false || chrome.webRequest.ResourceType.WEBSOCKET !== 'websocket'; +vAPI.webextFlavor = ''; +if ( + self.browser instanceof Object && + typeof self.browser.runtime.getBrowserInfo === 'function' +) { + self.browser.runtime.getBrowserInfo().then(function(info) { + vAPI.webextFlavor = info.vendor + '-' + info.name + '-' + info.version; + }); +} + var noopFunc = function(){}; /******************************************************************************/ @@ -301,14 +312,19 @@ vAPI.tabs.registerListeners = function() { }; var onCreatedNavigationTarget = function(details) { - //console.debug('onCreatedNavigationTarget: popup candidate tab id %d = "%s"', details.tabId, details.url); + if ( typeof details.url !== 'string' ) { + details.url = ''; + } if ( reGoodForWebRequestAPI.test(details.url) === false ) { details.frameId = 0; details.url = sanitizeURL(details.url); onNavigationClient(details); } if ( typeof vAPI.tabs.onPopupCreated === 'function' ) { - vAPI.tabs.onPopupCreated(details.tabId.toString(), details.sourceTabId.toString()); + vAPI.tabs.onPopupCreated( + details.tabId.toString(), + details.sourceTabId.toString() + ); } }; @@ -472,12 +488,19 @@ vAPI.tabs.open = function(details) { return; } + // https://github.com/gorhill/uBlock/issues/3053#issuecomment-332276818 + // - Do not try to lookup uBO's own pages with FF 55 or less. + if ( /^Mozilla-Firefox-5[2-5]\./.test(vAPI.webextFlavor) ) { + wrapper(); + return; + } + // https://developer.chrome.com/extensions/tabs#method-query // "Note that fragment identifiers are not matched." // It's a lie, fragment identifiers ARE matched. So we need to remove the // fragment. - var pos = targetURL.indexOf('#'); - var targetURLWithoutHash = pos === -1 ? targetURL : targetURL.slice(0, pos); + var pos = targetURL.indexOf('#'), + targetURLWithoutHash = pos === -1 ? targetURL : targetURL.slice(0, pos); chrome.tabs.query({ url: targetURLWithoutHash }, function(tabs) { if ( chrome.runtime.lastError ) { /* noop */ } diff --git a/platform/chromium/vapi-common.js b/platform/chromium/vapi-common.js index f49f5e420..a376ac6e3 100644 --- a/platform/chromium/vapi-common.js +++ b/platform/chromium/vapi-common.js @@ -77,8 +77,23 @@ setScriptDirection(vAPI.i18n('@@ui_locale')); /******************************************************************************/ +// https://github.com/gorhill/uBlock/issues/3057 +// - webNavigation.onCreatedNavigationTarget become broken on Firefox when we +// try to make the popup panel close itself. + vAPI.closePopup = function() { - window.open('','_self').close(); + if ( + self.browser instanceof Object && + typeof self.browser.runtime.getBrowserInfo === 'function' + ) { + self.browser.runtime.getBrowserInfo().then(function(info) { + if ( info.name !== 'Firefox' ) { + window.open('', '_self').close(); + } + }); + } else { + window.open('', '_self').close(); + } }; /******************************************************************************/ diff --git a/src/js/popup.js b/src/js/popup.js index 09587df21..f5fb819ed 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -632,7 +632,7 @@ var gotoPick = function() { /******************************************************************************/ var gotoURL = function(ev) { - if ( this.hasAttribute('href') === false) { + if ( this.hasAttribute('href') === false ) { return; }