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(
{
viewport: { height: 400, width: 900 },
// recordVideo: { dir: 'videos/' }
proxy: {
server: proxyOptions.server,
username: proxyOptions.username ? proxyOptions.username : undefined,
password: proxyOptions.password ? proxyOptions.password : undefined,
}
}
);
const contextOptions: any = {
viewport: { height: 400, width: 900 },
// recordVideo: { dir: 'videos/' }
};
if (proxyOptions.server) {
contextOptions.proxy = {
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();
const blocker = await PlaywrightBlocker.fromPrebuiltAdsAndTracking(fetch);
await blocker.enableBlockingInPage(this.currentPage);