diff --git a/src/js/webrequest.js b/src/js/webrequest.js index f3d44c513c..769d6dea04 100644 --- a/src/js/webrequest.js +++ b/src/js/webrequest.js @@ -51,6 +51,10 @@ function onBeforeRequest(details) { type = details.type, url = details.url; + if (utils.isRestrictedUrl(url)) { + return {}; + } + if (type == "main_frame") { forgetTab(tab_id); badger.recordFrame(tab_id, frame_id, url); @@ -68,7 +72,7 @@ function onBeforeRequest(details) { return {cancel: true}; } - if (_isTabChromeInternal(tab_id)) { + if (tab_id < 0) { return {}; } @@ -142,8 +146,8 @@ function onBeforeSendHeaders(details) { type = details.type, url = details.url; - if (_isTabChromeInternal(tab_id)) { - // DNT policy requests: strip cookies + if (tab_id < 0 || utils.isRestrictedUrl(url)) { + // strip cookies from DNT policy requests if (type == "xmlhttprequest" && url.endsWith("/.well-known/dnt-policy.txt")) { // remove Cookie headers let newHeaders = []; @@ -158,6 +162,7 @@ function onBeforeSendHeaders(details) { }; } + // ignore otherwise return {}; } @@ -222,8 +227,8 @@ function onHeadersReceived(details) { var tab_id = details.tabId, url = details.url; - if (_isTabChromeInternal(tab_id)) { - // DNT policy responses: strip cookies, reject redirects + if (tab_id < 0 || utils.isRestrictedUrl(url)) { + // strip cookies, reject redirects from DNT policy responses if (details.type == "xmlhttprequest" && url.endsWith("/.well-known/dnt-policy.txt")) { // if it's a redirect, cancel it if (details.statusCode >= 300 && details.statusCode < 400) { @@ -245,6 +250,7 @@ function onHeadersReceived(details) { }; } + // ignore otherwise return {}; } @@ -492,26 +498,6 @@ function checkAction(tabId, requestHost, frameId) { return badger.storage.getBestAction(requestHost); } -/** - * Checks if the tab is chrome internal - * - * @param {Integer} tabId Id of the tab to test - * @returns {boolean} Returns true if the tab is chrome internal - * @private - */ -function _isTabChromeInternal(tabId) { - if (tabId < 0) { - return true; - } - - let frameData = badger.getFrameData(tabId); - if (!frameData || !frameData.url.startsWith("http")) { - return true; - } - - return false; -} - /** * Checks if the tab is a chrome-extension tab * @@ -660,11 +646,6 @@ function dispatcher(request, sender, sendResponse) { return sendResponse(); } - // Ignore requests from internal Chrome tabs. - if (_isTabChromeInternal(sender.tab.id)) { - return sendResponse(); - } - let requestHost = window.extractHostFromURL(request.frameUrl); // Ignore requests that aren't from a third party.