From fee13e7fefdc91e23a72f7d78cd61305fd722f9f Mon Sep 17 00:00:00 2001 From: amhsirak Date: Sun, 22 Dec 2024 22:05:45 +0530 Subject: [PATCH 1/3] feat: gracefully proceed if !adblocker --- .../browser-management/classes/RemoteBrowser.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/server/src/browser-management/classes/RemoteBrowser.ts b/server/src/browser-management/classes/RemoteBrowser.ts index 31aceada..2c45d146 100644 --- a/server/src/browser-management/classes/RemoteBrowser.ts +++ b/server/src/browser-management/classes/RemoteBrowser.ts @@ -245,10 +245,17 @@ export class RemoteBrowser { await this.setupPageEventListeners(this.currentPage); - const blocker = await PlaywrightBlocker.fromLists(fetch, ['https://easylist.to/easylist/easylist.txt']); - await blocker.enableBlockingInPage(this.currentPage); - this.client = await this.currentPage.context().newCDPSession(this.currentPage); - await blocker.disableBlockingInPage(this.currentPage); + try { + const blocker = await PlaywrightBlocker.fromLists(fetch, ['https://easylist.to/easylist/easylist.txt']); + await blocker.enableBlockingInPage(this.currentPage); + this.client = await this.currentPage.context().newCDPSession(this.currentPage); + await blocker.disableBlockingInPage(this.currentPage); + console.log('Adblocker initialized'); + } catch (error: any) { + console.warn('Failed to initialize adblocker, continuing without it:', error.message); + // Still need to set up the CDP session even if blocker fails + this.client = await this.currentPage.context().newCDPSession(this.currentPage); + } }; /** From 584433e3f775f44c705c6e2a9152d77d006635fb Mon Sep 17 00:00:00 2001 From: amhsirak Date: Sun, 22 Dec 2024 22:08:56 +0530 Subject: [PATCH 2/3] feat: try-catch handling for adblocker in core --- maxun-core/src/interpret.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/maxun-core/src/interpret.ts b/maxun-core/src/interpret.ts index 14d8f46e..bc99c92f 100644 --- a/maxun-core/src/interpret.ts +++ b/maxun-core/src/interpret.ts @@ -111,13 +111,21 @@ export default class Interpreter extends EventEmitter { private async applyAdBlocker(page: Page): Promise { if (this.blocker) { - await this.blocker.enableBlockingInPage(page); + try { + await this.blocker.enableBlockingInPage(page); + } catch (err) { + this.log(`Ad-blocker operation failed:`, Level.ERROR); + } } } private async disableAdBlocker(page: Page): Promise { if (this.blocker) { - await this.blocker.disableBlockingInPage(page); + try { + await this.blocker.disableBlockingInPage(page); + } catch (err) { + this.log(`Ad-blocker operation failed:`, Level.ERROR); + } } } From 58f92a35dc6eace6b58f095678a684c886da91b3 Mon Sep 17 00:00:00 2001 From: amhsirak Date: Mon, 23 Dec 2024 00:03:20 +0530 Subject: [PATCH 3/3] feat: try-catch handling for adblocker in core --- maxun-core/src/interpret.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/maxun-core/src/interpret.ts b/maxun-core/src/interpret.ts index bc99c92f..c581954d 100644 --- a/maxun-core/src/interpret.ts +++ b/maxun-core/src/interpret.ts @@ -670,7 +670,11 @@ export default class Interpreter extends EventEmitter { const workflowCopy: Workflow = JSON.parse(JSON.stringify(workflow)); // apply ad-blocker to the current page - await this.applyAdBlocker(p); + try { + await this.applyAdBlocker(p); + } catch (error) { + this.log(`Failed to apply ad-blocker: ${error.message}`, Level.ERROR); + } const usedActions: string[] = []; let selectors: string[] = []; let lastAction = null;