On this page
Puppeteer controls Chrome, and Chrome takes its proxy from a command-line flag. Chrome ignores any username and password written into that flag, so the credentials go in a separate step with page.authenticate(). The examples use ES modules; save them as .mjs files or set "type": "module" in package.json.
Basic setup
npm install puppeteer
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch({
args: ['--proxy-server=http://HOST:PORT'],
});
const page = await browser.newPage();
await page.authenticate({ username: 'USERNAME', password: 'PASSWORD' });
await page.goto('https://api.ipify.org?format=json', { waitUntil: 'domcontentloaded' });
console.log(await page.evaluate(() => document.body.innerText));
await browser.close();
Things to know:
- Call
page.authenticate()on every new page, before its first navigation. Pages the site opens itself, such as popups, need it too. - Use the HTTP endpoint and port from your dashboard. Put only the host and port in
--proxy-server, never the username and password. - HTTPS websites work normally. Chrome tunnels them through the proxy.
A separate proxy per browser context
Each browser context can use its own proxy, which lets one browser run several sessions side by side:
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch();
const context = await browser.createBrowserContext({
proxyServer: 'http://HOST:PORT',
});
const page = await context.newPage();
await page.authenticate({ username: 'USERNAME', password: 'PASSWORD' });
await page.goto('https://api.ipify.org?format=json');
console.log(await page.evaluate(() => document.body.innerText));
await browser.close();
createBrowserContext() is the current name; Puppeteer versions before 22 called it createIncognitoBrowserContext(). Contexts don't share cookies or storage, so each one behaves like a separate visitor.
If your sticky lines share the same host and port and differ only in the username, you can also give each page its own credentials with page.authenticate().
SOCKS5
Chrome supports SOCKS5 proxies, but not SOCKS5 with a username and password, and page.authenticate() can't change that. Since FreshProxies proxies use authentication, use the HTTP endpoint with Puppeteer.
Bypass the proxy for some hosts
const browser = await puppeteer.launch({
args: [
'--proxy-server=http://HOST:PORT',
'--proxy-bypass-list=localhost;127.0.0.1;*.internal.example',
],
});
Separate the entries with semicolons. For a browser context, pass proxyBypassList as an array next to proxyServer.
Save traffic by blocking heavy files
Residential and mobile traffic is billed per GB. If you only need the page text, block images, media and fonts:
await page.setRequestInterception(true);
page.on('request', (request) => {
if (['image', 'media', 'font'].includes(request.resourceType())) {
request.abort();
} else {
request.continue();
}
});
Request interception turns off the page cache, so check the traffic used before and after to confirm the saving on your pages.
Check the result
Before real work, check the exit IP as in the examples above. To confirm that the browser doesn't reveal your real IP through WebRTC, load the WebRTC leak test in the same context. For long-running sessions, use a sticky line; rotating vs sticky sessions explains why. If you'd rather pass the username and password straight into the launch options, see the Playwright guide. When a page doesn't load through the proxy, start with troubleshooting.