From b893b34333af5e045ec547f48372f0c63c8a6bea Mon Sep 17 00:00:00 2001 From: Manish Jethani Date: Fri, 13 Aug 2021 19:15:29 +0530 Subject: [PATCH] Add Adblock Plus whitelisting logic --- .../blockers/adblockplus.js | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/adblocker-benchmarks/blockers/adblockplus.js b/packages/adblocker-benchmarks/blockers/adblockplus.js index fb94939dce..52395f254b 100644 --- a/packages/adblocker-benchmarks/blockers/adblockplus.js +++ b/packages/adblocker-benchmarks/blockers/adblockplus.js @@ -86,12 +86,32 @@ module.exports = class AdblockPlus { matchDebug(request) { const url = parseURL(request.url); const sourceURL = parseURL(request.frameUrl); + + // The whitelisting logic is based on + // https://github.com/adblockplus/adblockpluschrome/blob/1affa87724a7334e589c9a7bb197da8d5e5bf878/lib/requestBlocker.js#L187 + // + // Since the current request data set does not give us a frame hierarchy, + // we assume that the request is from a top-level frame. + const documentFilter = this.matcher.match( + sourceURL, + contentTypes.DOCUMENT, + ); + + if (documentFilter !== null) { + return documentFilter.text; + } + + const specificOnly = this.matcher.match( + sourceURL, + contentTypes.GENERICBLOCK, + ) !== null; + const filter = this.matcher.match( url, contentTypes[resourceTypes.get(request.type) || 'OTHER'], sourceURL.hostname, null, - false, + specificOnly, ); return filter === null ? null : filter.text;