Index: lib/requestBlocker.js |
=================================================================== |
--- a/lib/requestBlocker.js |
+++ b/lib/requestBlocker.js |
@@ -24,30 +24,46 @@ |
const {defaultMatcher} = require("matcher"); |
const {FilterNotifier} = require("filterNotifier"); |
const {Prefs} = require("prefs"); |
const {checkWhitelisted, getKey} = require("whitelisting"); |
const {stringifyURL, extractHostFromFrame, isThirdParty} = require("url"); |
const {port} = require("messaging"); |
const devtools = require("devtools"); |
-// Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests. |
+// Chrome and Firefox can't distinguish between OBJECT_SUBREQUEST and OBJECT |
Sebastian Noack
2017/05/18 21:33:41
Nit: Thanks for updating the comment, but it's sti
Manish Jethani
2017/05/18 21:49:34
Done.
|
+// requests. |
RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; |
+let resourceTypeMapping = new Map([ |
+ ["beacon", "PING"], |
+ ["imageset", "IMAGE"], |
+ ["sub_frame", "SUBDOCUMENT"] |
+]); |
+ |
+let typeMasks = new Map( |
+ Object.keys(chrome.webRequest.ResourceType) |
+ .map(typeKey => chrome.webRequest.ResourceType[typeKey]) |
+ .map(type => [type, RegExpFilter.typeMap[resourceTypeMapping.get(type)] || |
+ RegExpFilter.typeMap[type.toUpperCase()] || |
+ RegExpFilter.typeMap.OTHER]) |
+); |
+ |
function onBeforeRequestAsync(page, url, type, docDomain, |
thirdParty, sitekey, |
specificOnly, filter) |
{ |
if (filter) |
FilterNotifier.emit("filter.hitCount", filter, 0, 0, page); |
if (devtools) |
{ |
devtools.logRequest( |
- page, url, type, docDomain, |
+ page, url, |
+ resourceTypeMapping.get(type) || type.toUpperCase(), docDomain, |
Sebastian Noack
2017/05/18 21:33:42
In case of the resource types we handle as OTHER,
Manish Jethani
2017/05/18 21:49:34
Oops, somehow I missed this. Fixed.
|
thirdParty, sitekey, |
specificOnly, filter |
); |
} |
} |
ext.webRequest.onBeforeRequest.addListener((url, type, page, frame) => |
{ |
@@ -59,17 +75,17 @@ |
let thirdParty = isThirdParty(url, docDomain); |
let sitekey = getKey(page, frame); |
let specificOnly = !!checkWhitelisted( |
page, frame, RegExpFilter.typeMap.GENERICBLOCK |
); |
let filter = defaultMatcher.matchesAny( |
- urlString, RegExpFilter.typeMap[type], |
+ urlString, typeMasks.get(type), |
docDomain, thirdParty, sitekey, specificOnly |
); |
setTimeout(onBeforeRequestAsync, 0, page, urlString, |
type, docDomain, |
thirdParty, sitekey, |
specificOnly, filter); |