Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/requestBlocker.js

Issue 29739603: Issue 6544 - Prevent requests sent by Chrome or Adblock Plus from being blocked (Closed)
Patch Set: Rebased Created April 9, 2018, 9:30 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/devtools.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/requestBlocker.js
===================================================================
--- a/lib/requestBlocker.js
+++ b/lib/requestBlocker.js
@@ -30,6 +30,9 @@
const {port} = require("./messaging");
const devtools = require("./devtools");
+const extensionProtocol = new URL(browser.extension.getURL("")).protocol;
+const ignoredOrigins = new Set([extensionProtocol, "chrome:"]);
+
// Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests.
if (!browser.webRequest.ResourceType ||
!("OBJECT_SUBREQUEST" in browser.webRequest.ResourceType))
@@ -129,23 +132,24 @@
url.protocol != "ws:" && url.protocol != "wss:")
return;
- let originUrl = null;
- if (details.originUrl)
- {
- originUrl = new URL(details.originUrl);
+ // Firefox provides us with the full origin URL, while Chromium (>=63)
+ // provides only the protocol + host of the (top-level) document which
+ // the request originates from through the "initiator" property.
+ let originUrl = details.originUrl ? new URL(details.originUrl) :
+ details.initiator ? new URL(details.initiator) : null;
- // Firefox (only) allows to intercept requests sent by the browser
- // and other extensions. We don't want to block these.
- if (originUrl.protocol == "chrome:" ||
- originUrl.protocol == "moz-extension:")
- return;
- }
- // Fallback to "initiator" on Chrome >=63. It doesn't include the
- // path (unlike "originUrl" on Firefox), but is still good enough
- // (in case the tab/frame is unknown) for the $domain filter option
- // and most document exception rules which only match the domain part.
- else if (details.initiator)
- originUrl = new URL(details.initiator);
+ // Ignore requests sent by extensions or by the browser itself:
+ // * Firefox intercepts requests sent by any extensions, indicated with
+ // an "originURL" starting with "moz-extension:".
+ // * Chromium intercepts requests sent by this extension only, indicated
+ // on Chromium >=63 with an "initiator" starting with "chrome-extension:".
+ // * On Firefox, requests that don't relate to any document or extension are
+ // indicated with an "originUrl" starting with "chrome:".
+ // * On Chromium >=63, requests that don't relate to any document or extension
+ // have no "initiator". But since on older Chromium versions, no request
+ // has an "initiator", we have to check for the tabId as well.
+ if (originUrl ? ignoredOrigins.has(originUrl.protocol) : details.tabId == -1)
+ return;
let page = null;
let frame = null;
« no previous file with comments | « lib/devtools.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld