Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion maxun-core/src/interpret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default class Interpreter extends EventEmitter {
};
}

PlaywrightBlocker.fromPrebuiltAdsAndTracking(fetch).then(blocker => {
PlaywrightBlocker.fromLists(fetch, ['https://easylist.to/easylist/easylist.txt']).then(blocker => {
this.blocker = blocker;
}).catch(err => {
this.log(`Failed to initialize ad-blocker:`, Level.ERROR);
Expand Down
2 changes: 1 addition & 1 deletion server/src/browser-management/classes/RemoteBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class RemoteBrowser {
// await this.currentPage.setExtraHTTPHeaders({
// 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
// });
const blocker = await PlaywrightBlocker.fromPrebuiltAdsAndTracking(fetch);
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);
Comment on lines +183 to 186
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider improving the ad-blocker initialization.

  1. The EasyList URL should be configurable rather than hardcoded to allow for easy updates and maintenance.
  2. The blocker is enabled and immediately disabled in sequence, which seems unnecessary.

Consider these improvements:

-        const blocker = await PlaywrightBlocker.fromLists(fetch, ['https://easylist.to/easylist/easylist.txt']);
+        const EASYLIST_URL = process.env.EASYLIST_URL || 'https://easylist.to/easylist/easylist.txt';
+        try {
+            const blocker = await PlaywrightBlocker.fromLists(fetch, [EASYLIST_URL]);
+            await blocker.enableBlockingInPage(this.currentPage);
+        } catch (error) {
+            logger.log('error', `Failed to initialize ad-blocker: ${error.message}`);
+        }

Committable suggestion skipped: line range outside the PR's diff.

Expand Down