Skip to content

Commit 73a3dc2

Browse files
authoredApr 5, 2024··
Adblocker: enabled preprocessor (#96)
1 parent 18b69c1 commit 73a3dc2

File tree

3 files changed

+77
-65
lines changed

3 files changed

+77
-65
lines changed
 

‎modules/adblocker/sources/manager.es

+13-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,21 @@ import { nextIdle } from '../core/decorators';
1212
import pacemaker from '../core/services/pacemaker';
1313
import { fetchJSON, fetchText, fetchTypedArray } from '../core/http';
1414
import persistentMapFactory from '../core/persistence/map';
15+
import { isMobile, isFirefox, isChromium, isEdge } from '../core/platform';
1516

1617
import logger from './logger';
1718
import config from './config';
1819
import getEnabledRegions from './regions';
1920

21+
const ENV = new Map([
22+
['ext_ghostery', true],
23+
['cap_html_filtering', isFirefox],
24+
['env_firefox', isFirefox],
25+
['env_chromium', isChromium],
26+
['env_edge', isEdge],
27+
['env_mobile', isMobile],
28+
]);
29+
2030
/**
2131
* Manages the adblocker WebExtensionEngine state. It allows to initialize, update,
2232
* cache and reload the engine. It takes care of fetching and using the
@@ -329,7 +339,7 @@ export default class EngineManager {
329339
// updated and `false` otherwise.
330340
timer = this.stopwatch('update engine (update)', 'adblocker');
331341
const cumulativeDiff = AdblockerLib.mergeDiffs(diffs);
332-
let updated = this.engine.updateFromDiff(cumulativeDiff);
342+
let updated = this.engine.updateFromDiff(cumulativeDiff, ENV);
333343
timer.stop();
334344

335345
if (updated === true) {
@@ -384,6 +394,7 @@ export default class EngineManager {
384394
timer = this.stopwatch('deserialize engine from cache', 'adblocker');
385395
try {
386396
this.engine = AdblockerLib.WebExtensionBlocker.deserialize(serialized);
397+
this.engine.updateEnv(ENV);
387398
} catch (ex) {
388399
// In case there is a mismatch between the version of the code
389400
// and the serialization format of the engine on disk, we might
@@ -429,6 +440,7 @@ export default class EngineManager {
429440
timer = this.stopwatch('deserialize remote engine', 'adblocker');
430441
try {
431442
this.engine = AdblockerLib.WebExtensionBlocker.deserialize(serialized);
443+
this.engine.updateEnv(ENV);
432444
} catch (ex) {
433445
logger.error('exception while loading remote engine', ex);
434446
return null;

‎package-lock.json

+62-62
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@
135135
},
136136
"dependencies": {
137137
"@cliqz-oss/dexie": "^2.0.4",
138-
"@cliqz/adblocker-webextension": "^1.26.9",
139-
"@cliqz/adblocker-webextension-cosmetics": "^1.26.9",
138+
"@cliqz/adblocker-webextension": "^1.27.0",
139+
"@cliqz/adblocker-webextension-cosmetics": "^1.27.0",
140140
"@cliqz/url-parser": "^1.1.5",
141141
"abortcontroller-polyfill": "^1.5.0",
142142
"anonymous-credentials": "https://github.com/whotracksme/anonymous-credentials/releases/download/1.0.0/anonymous-credentials-1.0.0.tgz",

0 commit comments

Comments
 (0)
Please sign in to comment.