fix: apply proxy config only if proxy server available

This commit is contained in:
karishmas6
2024-10-27 18:05:08 +05:30
parent fb8935e912
commit 744e8df558

View File

@@ -104,17 +104,20 @@ export class RemoteBrowser {
}), }),
}; };
} }
this.context = await this.browser.newContext( const contextOptions: any = {
{ viewport: { height: 400, width: 900 },
viewport: { height: 400, width: 900 }, // recordVideo: { dir: 'videos/' }
// recordVideo: { dir: 'videos/' } };
proxy: {
server: proxyOptions.server, if (proxyOptions.server) {
username: proxyOptions.username ? proxyOptions.username : undefined, contextOptions.proxy = {
password: proxyOptions.password ? proxyOptions.password : undefined, server: proxyOptions.server,
} username: proxyOptions.username ? proxyOptions.username : undefined,
} password: proxyOptions.password ? proxyOptions.password : undefined,
); };
}
this.context = await this.browser.newContext(contextOptions);
this.currentPage = await this.context.newPage(); this.currentPage = await this.context.newPage();
const blocker = await PlaywrightBlocker.fromPrebuiltAdsAndTracking(fetch); const blocker = await PlaywrightBlocker.fromPrebuiltAdsAndTracking(fetch);
await blocker.enableBlockingInPage(this.currentPage); await blocker.enableBlockingInPage(this.currentPage);