Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const launchPuppeteerWithProxy = async (puppeteer, opts) => {
// Parse and validate proxy URL
const parsedProxyUrl = parseUrl(opts.proxyUrl);
if (!parsedProxyUrl.host || !parsedProxyUrl.port) {
throw new Error('Invalid "proxyUrl" option: both hostname and port must be provided.');
}
if (!/^(http|https|socks4|socks5)$/.test(parsedProxyUrl.scheme)) {
throw new Error(`Invalid "proxyUrl" option: Unsupported scheme (${parsedProxyUrl.scheme}).`);
}
// Anonymize proxy URL if it has username or password
let anonymizedProxyUrl = null;
if (parsedProxyUrl.username || parsedProxyUrl.password) {
if (parsedProxyUrl.scheme !== 'http') {
throw new Error('Invalid "proxyUrl" option: authentication is only supported for HTTP proxy type.');
}
anonymizedProxyUrl = await anonymizeProxy(opts.proxyUrl);
}