Skip to content

Commit

Permalink
Adblocker: enabled preprocessor (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmod authored Apr 5, 2024
1 parent 18b69c1 commit 73a3dc2
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 65 deletions.
14 changes: 13 additions & 1 deletion modules/adblocker/sources/manager.es
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,21 @@ import { nextIdle } from '../core/decorators';
import pacemaker from '../core/services/pacemaker';
import { fetchJSON, fetchText, fetchTypedArray } from '../core/http';
import persistentMapFactory from '../core/persistence/map';
import { isMobile, isFirefox, isChromium, isEdge } from '../core/platform';

import logger from './logger';
import config from './config';
import getEnabledRegions from './regions';

const ENV = new Map([
['ext_ghostery', true],
['cap_html_filtering', isFirefox],
['env_firefox', isFirefox],
['env_chromium', isChromium],
['env_edge', isEdge],
['env_mobile', isMobile],
]);

/**
* Manages the adblocker WebExtensionEngine state. It allows to initialize, update,
* cache and reload the engine. It takes care of fetching and using the
Expand Down Expand Up @@ -329,7 +339,7 @@ export default class EngineManager {
// updated and `false` otherwise.
timer = this.stopwatch('update engine (update)', 'adblocker');
const cumulativeDiff = AdblockerLib.mergeDiffs(diffs);
let updated = this.engine.updateFromDiff(cumulativeDiff);
let updated = this.engine.updateFromDiff(cumulativeDiff, ENV);
timer.stop();

if (updated === true) {
Expand Down Expand Up @@ -384,6 +394,7 @@ export default class EngineManager {
timer = this.stopwatch('deserialize engine from cache', 'adblocker');
try {
this.engine = AdblockerLib.WebExtensionBlocker.deserialize(serialized);
this.engine.updateEnv(ENV);
} catch (ex) {
// In case there is a mismatch between the version of the code
// and the serialization format of the engine on disk, we might
Expand Down Expand Up @@ -429,6 +440,7 @@ export default class EngineManager {
timer = this.stopwatch('deserialize remote engine', 'adblocker');
try {
this.engine = AdblockerLib.WebExtensionBlocker.deserialize(serialized);
this.engine.updateEnv(ENV);
} catch (ex) {
logger.error('exception while loading remote engine', ex);
return null;
Expand Down
124 changes: 62 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@
},
"dependencies": {
"@cliqz-oss/dexie": "^2.0.4",
"@cliqz/adblocker-webextension": "^1.26.9",
"@cliqz/adblocker-webextension-cosmetics": "^1.26.9",
"@cliqz/adblocker-webextension": "^1.27.0",
"@cliqz/adblocker-webextension-cosmetics": "^1.27.0",
"@cliqz/url-parser": "^1.1.5",
"abortcontroller-polyfill": "^1.5.0",
"anonymous-credentials": "https://github.com/whotracksme/anonymous-credentials/releases/download/1.0.0/anonymous-credentials-1.0.0.tgz",
Expand Down

0 comments on commit 73a3dc2

Please sign in to comment.