What is the best way to set up multiple proxies with puppeteer? I tried the following:
const puppeteer = require('puppeteer');
(async () => {
const proxies = [
'socks5://myusername:mypassword@myhost:myport',
'socks5://myusername:mypassword@myhost:myport',
'socks5://myusername:mypassword@myhost:myport'
];
const openWindow = async (proxyUrl) => {
const browser = await puppeteer.launch({
headless: false,
args: [`--proxy-server=${proxyUrl}`]
});
const page = await browser.newPage();
page.setDefaultNavigationTimeout(0);
await page.authenticate({
username: 'myusername', // Replace with your proxy username
password: 'mypassword' // Replace with your proxy password
});
await page.setViewport({
width: 992,
height: 607
});
await page.goto('https://dnsleaktest.com');
console.log(`Window opened with proxy: ${proxyUrl}`);
};
// Open windows with proxies
for (const proxy of proxies) {
// Open multiple windows per proxy
for (let i = 0; i < 3; i++) {
await openWindow(proxy);
}
}
console.log('All windows opened.');
})();
However, it does not work and I get the following message instead:
Error: net::ERR_NO_SUPPORTED_PROXIES at https://dnsleaktest.com
Background: The application previously worked with a single proxy configuration, but the issue arose when attempting to introduce support for multiple proxies.
Each scraper instance runs in its Chrome window, with one proxy configured per window for isolation and parallel scraping purposes.
Single Window Code:
const puppeteer = require('puppeteer');
const proxy = 'myip:myport';
const username = 'myusername';
const password = 'mypassword';
(async () => {
// Pass proxy URL into the --proxy-server arg
const browser = await puppeteer.launch({
args: [`--proxy-server=${proxy}`],
headless: false,
ignoreHTTPSErrors: true
});
const page = await browser.newPage()
page.setDefaultNavigationTimeout(0);
// Authenticate your proxy with the username and password defined above
await page.authenticate({ username, password });
await page.goto('https://dnsleaktest.com');
})();