Skip to content

Commit

Permalink
Fix (not) recording tab data for extension pages
Browse files Browse the repository at this point in the history
Broken by updating onBeforeRequest() to listen to all URLs (instead of
just http and https URLs) in fb68766
  • Loading branch information
ghostwords committed Nov 1, 2019
1 parent 47dbaba commit 0de95d8
Showing 1 changed file with 11 additions and 30 deletions.
41 changes: 11 additions & 30 deletions src/js/webrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -68,7 +72,7 @@ function onBeforeRequest(details) {
return {cancel: true};
}

if (_isTabChromeInternal(tab_id)) {
if (tab_id < 0) {
return {};
}

Expand Down Expand Up @@ -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 = [];
Expand All @@ -158,6 +162,7 @@ function onBeforeSendHeaders(details) {
};
}

// ignore otherwise
return {};
}

Expand Down Expand Up @@ -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) {
Expand All @@ -245,6 +250,7 @@ function onHeadersReceived(details) {
};
}

// ignore otherwise
return {};
}

Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 0de95d8

Please sign in to comment.