From 1518d01a66deb04b5dc27323fc8d73e78bc8b8a5 Mon Sep 17 00:00:00 2001 From: Alexei Date: Mon, 18 Nov 2019 12:23:05 -0500 Subject: [PATCH] Add TODO to look into localStorage detection bug This hides "window.injectScript undefined" console errors in Chrome that started in b7e9aea694e07a1f744259308779187e4fc9bd42 The aforementioned commit merely made the problem more visible, however. The underlying issue (FRAME_URL/injectScript from the utils.js content script sometimes being undefined in the supercookie.js content script) was already present at that point. --- src/js/contentscripts/supercookie.js | 3 +++ src/js/webrequest.js | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/js/contentscripts/supercookie.js b/src/js/contentscripts/supercookie.js index 6f7c00c671..3d8de29c4e 100644 --- a/src/js/contentscripts/supercookie.js +++ b/src/js/contentscripts/supercookie.js @@ -119,6 +119,9 @@ if (window.top == window) { // // could then remove test workarounds like // https://github.com/EFForg/privacybadger/commit/39d5d0899e22d1c451d429e44553c5f9cad7fc46 + +// TODO sometimes contentscripts/utils.js isn't here?! +// TODO window.FRAME_URL / window.injectScript are undefined ... chrome.runtime.sendMessage({ type: "checkEnabledAndThirdParty", frameUrl: window.FRAME_URL diff --git a/src/js/webrequest.js b/src/js/webrequest.js index 52dde75135..0257fec05a 100644 --- a/src/js/webrequest.js +++ b/src/js/webrequest.js @@ -682,14 +682,15 @@ function dispatcher(request, sender, sendResponse) { return sendResponse(); } - let requestHost = window.extractHostFromURL(request.frameUrl); + let frame_host = window.extractHostFromURL(request.frameUrl), + tab_host = window.extractHostFromURL(sender.tab.url); // Ignore requests that aren't from a third party. - if (!utils.isThirdPartyDomain(requestHost, window.extractHostFromURL(sender.tab.url))) { + if (!frame_host || !utils.isThirdPartyDomain(frame_host, tab_host)) { return sendResponse(); } - let action = checkAction(sender.tab.id, requestHost); + let action = checkAction(sender.tab.id, frame_host); sendResponse(action == constants.COOKIEBLOCK || action == constants.USER_COOKIE_BLOCK); break; @@ -770,7 +771,7 @@ function dispatcher(request, sender, sendResponse) { } case "supercookieReport": { - if (badger.hasSuperCookie(request.data)) { + if (request.frameUrl && badger.hasSuperCookie(request.data)) { recordSuperCookie(sender.tab.id, request.frameUrl); } break; @@ -780,7 +781,9 @@ function dispatcher(request, sender, sendResponse) { let tab_host = window.extractHostFromURL(sender.tab.url), frame_host = window.extractHostFromURL(request.frameUrl); - sendResponse(badger.isPrivacyBadgerEnabled(tab_host) && utils.isThirdPartyDomain(frame_host, tab_host)); + sendResponse(frame_host && + badger.isPrivacyBadgerEnabled(tab_host) && + utils.isThirdPartyDomain(frame_host, tab_host)); break; }