From f560f2c2133e3ca3eab8531806004587ab9e7e1e Mon Sep 17 00:00:00 2001 From: Bianca Danforth Date: Mon, 19 Jun 2017 07:18:30 -0700 Subject: [PATCH] Remove moz-extension:* paths from capture. Fixes #49. (#62) --- js/capture.js | 27 ++++++++++++++++++++------- manifest.json | 1 - 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/js/capture.js b/js/capture.js index d0febff..7adb707 100644 --- a/js/capture.js +++ b/js/capture.js @@ -10,10 +10,25 @@ const capture = { addListeners() { // listen for each HTTP response browser.webRequest.onResponseStarted.addListener( - this.sendThirdParty, + (response) => this.sendThirdParty(response), {urls: ['']}); // listen for tab updates - browser.tabs.onUpdated.addListener(this.sendFirstParty); + browser.tabs.onUpdated.addListener( + (tabId, changeInfo, tab) => { + this.sendFirstParty(tabId, changeInfo, tab); + }); + }, + + // Returns true if the request should be stored, otherwise false. + shouldStore(tab) { + const documentUrl = new URL(tab.url); + // ignore about:*, moz-extension:* & non-visible tabs (like dev tools) + if (documentUrl.protocol !== 'about:' + && documentUrl.protocol !== 'moz-extension:' + && tab.id !== browser.tabs.TAB_ID_NONE) { + return true; + } + return false; }, // capture third party requests @@ -23,7 +38,8 @@ const capture = { const targetUrl = new URL(response.url); const originUrl = new URL(response.originUrl); - if (targetUrl.hostname !== documentUrl.hostname) { + if (targetUrl.hostname !== documentUrl.hostname + && this.shouldStore(tab)) { const data = { document: documentUrl.hostname, target: targetUrl.hostname, @@ -41,10 +57,7 @@ const capture = { // capture first party requests sendFirstParty(tabId, changeInfo, tab) { const documentUrl = new URL(tab.url); - // ignore about:* pages and non-visible tabs - if (tab.status === 'complete' - && documentUrl.protocol !== 'about:' - && tabId !== browser.tabs.TAB_ID_NONE) { + if (tab.status === 'complete' && this.shouldStore(tab)) { const data = { faviconUrl: tab.favIconUrl }; store.setFirstParty(documentUrl.hostname, data); } diff --git a/manifest.json b/manifest.json index df8fc4e..2e2cbc6 100644 --- a/manifest.json +++ b/manifest.json @@ -25,7 +25,6 @@ "background": { "scripts": [ - "js/store.js", "js/capture.js", "js/store.js", "js/viz.js",