temp: remove adblocker

This commit is contained in:
amhsirak
2026-01-04 22:42:22 +05:30
parent 5358a6ac93
commit 2c795af858
2 changed files with 8 additions and 46 deletions

View File

@@ -30,7 +30,6 @@
"author": "Maxun", "author": "Maxun",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"dependencies": { "dependencies": {
"@cliqz/adblocker-playwright": "^1.31.3",
"@types/node": "22.7.9", "@types/node": "22.7.9",
"cross-fetch": "^4.0.0", "cross-fetch": "^4.0.0",
"joi": "^17.6.0", "joi": "^17.6.0",

View File

@@ -1,6 +1,5 @@
/* eslint-disable no-await-in-loop, no-restricted-syntax */ /* eslint-disable no-await-in-loop, no-restricted-syntax */
import { ElementHandle, Page, PageScreenshotOptions } from 'playwright-core'; import { ElementHandle, Page, PageScreenshotOptions } from 'playwright-core';
import { PlaywrightBlocker } from '@cliqz/adblocker-playwright';
import fetch from 'cross-fetch'; import fetch from 'cross-fetch';
import path from 'path'; import path from 'path';
@@ -70,7 +69,7 @@ export default class Interpreter extends EventEmitter {
private log: typeof log; private log: typeof log;
private blocker: PlaywrightBlocker | null = null; // private blocker: PlaywrightBlocker | null = null;
private cumulativeResults: Record<string, any>[] = []; private cumulativeResults: Record<string, any>[] = [];
@@ -125,13 +124,13 @@ export default class Interpreter extends EventEmitter {
}; };
} }
PlaywrightBlocker.fromLists(fetch, ['https://easylist.to/easylist/easylist.txt']).then(blocker => { // PlaywrightBlocker.fromLists(fetch, ['https://easylist.to/easylist/easylist.txt']).then(blocker => {
this.blocker = blocker; // this.blocker = blocker;
}).catch(err => { // }).catch(err => {
this.log(`Failed to initialize ad-blocker: ${err.message}`, Level.ERROR); // this.log(`Failed to initialize ad-blocker: ${err.message}`, Level.ERROR);
// Continue without ad-blocker rather than crashing // // Continue without ad-blocker rather than crashing
this.blocker = null; // this.blocker = null;
}) // })
} }
/** /**
@@ -148,26 +147,6 @@ export default class Interpreter extends EventEmitter {
return this.isAborted; return this.isAborted;
} }
private async applyAdBlocker(page: Page): Promise<void> {
if (this.blocker) {
try {
await this.blocker.enableBlockingInPage(page as any);
} catch (err) {
this.log(`Ad-blocker operation failed:`, Level.ERROR);
}
}
}
private async disableAdBlocker(page: Page): Promise<void> {
if (this.blocker) {
try {
await this.blocker.disableBlockingInPage(page as any);
} catch (err) {
this.log(`Ad-blocker operation failed:`, Level.ERROR);
}
}
}
// private getSelectors(workflow: Workflow, actionId: number): string[] { // private getSelectors(workflow: Workflow, actionId: number): string[] {
// const selectors: string[] = []; // const selectors: string[] = [];
@@ -2210,12 +2189,6 @@ export default class Interpreter extends EventEmitter {
workflowCopy = this.removeSpecialSelectors(workflowCopy); workflowCopy = this.removeSpecialSelectors(workflowCopy);
// apply ad-blocker to the current page
try {
await this.applyAdBlocker(p);
} catch (error) {
this.log(`Failed to apply ad-blocker: ${error.message}`, Level.ERROR);
}
const usedActions: string[] = []; const usedActions: string[] = [];
let selectors: string[] = []; let selectors: string[] = [];
let lastAction = null; let lastAction = null;
@@ -2495,16 +2468,6 @@ export default class Interpreter extends EventEmitter {
} }
} }
// Clear ad-blocker resources
if (this.blocker) {
try {
this.blocker = null;
this.log('Ad-blocker resources cleared', Level.DEBUG);
} catch (error: any) {
this.log(`Error cleaning up ad-blocker: ${error.message}`, Level.WARN);
}
}
// Clear accumulated data to free memory // Clear accumulated data to free memory
this.cumulativeResults = []; this.cumulativeResults = [];
this.namedResults = {}; this.namedResults = {};