Puppeteer is a capable browser automation tool by itself, but when you pair it with the right proxy setup, it becomes a true powerhouse.
You’ll learn how to combine Puppeteer with a proxy server setup to improve your web automation, scraping, and testing workflows.
We’ll also walk through how to plug in proxy credentials, set up rotating proxies, and explain proxy configuration strategies. Those should help you stay undetected, especially when dealing with anti-bot protections.
What is Puppeteer?
Puppeteer is a Node.js library that controls Chromium-based browsers or Chrome itself through the DevTools Protocol. It allows you to script user actions like clicking, typing, and navigating websites.
You may want to use Puppeteer for tasks like form submission, screenshot capturing, web scraping, and headless browser testing. It’s also popular for automating repetitive browser tasks or checking UI behaviors in apps.
Headless mode means that the browser runs without a visible interface. It’s faster and often used for web scraping. Headful mode, on the other hand, shows the browser window so you can see everything that’s happening. It’s more often used for debugging.
Puppeteer is a great option for the use cases mentioned above, but there are also other popular tools like Playwright and Selenium that excel in different areas of web scraping.
Why Use Proxies With Puppeteer?
Using a proxy server with Puppeteer gives you a better edge, especially if you’re accessing data-heavy sites or geo-blocked content. Proxies help mask your IP, avoid bans, and access region-locked pages.
They also allow you to make multiple requests without raising red flags. If you’re working with a proxy provider, you get access to large pools of IPs that can reduce the chance of getting blocked.
You can route traffic through different proxy servers based on region or other factors, and it makes your operations more flexible and secure.
How to Integrate Proxies With Puppeteer
Let’s go step-by-step and set up your Puppeteer proxy with a full proxy configuration.
1. Installing Dependencies
Start by installing Puppeteer via npm:
npm install puppeteer
You’ll also need a proxy provider that supplies you with a proxy address, proxy URL, and proxy credentials if required.
2. Adding Proxy Details
You can pass the proxy server via the --proxy-server argument.
const puppeteer = require("puppeteer");
(async () => {
const browser = await puppeteer.launch({ args: ["--proxy-server=http://your-proxy-address:port"], });
const page = await browser.newPage();
await page.goto("https://iproyal.com");
await browser.close();
})();
You’ll replace the “http://your-proxy-address:port” with your actual proxy URL or proxy address.
3. Handling Proxy Authentication
Some proxy servers require proxy credentials (username and password). Here’s how you can handle that:
await page.authenticate({
username: 'yourUsername',
password: 'yourPassword'
});
This is common when working with a proxy provider that gives premium or residential IPs. So, your code should now look like the example below:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({
args: ['--proxy-server=geo.iproyal.com:12321']
});
const page = await browser.newPage();
await page.authenticate({
username: 'yourUsername',
password: 'yourPassword'
});
await page.goto('https://iproyal.com');
await browser.close();
})();
4. Verifying Proxy Integration
After setting up your Puppeteer proxy, you can verify the IP used by opening a public IP-check page:
const response = await page.goto('https://api.ipify.org?format=json');
const body = await response.json();
console.log(body); // { ip: 'your-proxy-ip' }
It should show the IP from your proxy server, not your original one. If the IP looks different, it means that your proxy configuration works.
Rotating Proxies in Puppeteer
When doing large-scale scraping, using a single IP won’t cut it. Sites will detect and block it at some point. That’s why using rotating proxies is essential.
They help by rotating IPs, preventing bans, and making your access to target websites smoother. You’ve got two main strategies here: random rotation and sequential rotation.
Note that many proxy providers, IPRoyal included, can perform automatic proxy rotation for you. Check your provider’s documentation to see if such a feature is available. The following examples assume no such rotation is provided.
1. Random Rotation
This strategy is about picking a proxy URL from the list randomly. You’ll basically be pulling names from a hat. If that’s what works for you, it’s an easier and simpler option.
const puppeteer = require('puppeteer');
const proxies = [
'http://proxy1:port',
'http://proxy2:port',
'http://proxy3:port'
];
(async () => {
const randomProxy = proxies[Math.floor(Math.random() * proxies.length)];
const browser = await puppeteer.launch({
args: [`--proxy-server=${randomProxy}`]
});
const page = await browser.newPage();
await page.goto('https://httpbin.org/ip');
await browser.close();
})();
2. Sequential Rotation
This way, you go through multiple proxy servers in a specific order. This method is good when you want even traffic spread across each proxy server.
However, many proxy providers offer built-in rotating proxies that automatically rotate IPs on each request or at set intervals, so you don’t need to manage the rotation logic yourself.
const puppeteer = require('puppeteer');
const proxies = [
'proxy1.example.com:8080',
'proxy2.example.com:8080',
'proxy3.example.com:8080'
];
let currentIndex = 0;
function getNextProxy() {
const proxy = proxies[currentIndex];
currentIndex = (currentIndex + 1) % proxies.length;
return proxy;
}
async function testWithProxy() {
const browser = await puppeteer.launch({
args: [`--proxy-server=${getNextProxy()}`]
});
const page = await browser.newPage();
await page.goto('https://httpbin.org/ip');
console.log(`Tested with proxy: ${proxies[(currentIndex - 1 + proxies.length) % proxies.length]}`);
await browser.close();
}
(async () => {
try {
// Test each proxy
for (let i = 0; i < proxies.length; i++) {
await testWithProxy();
}
} catch (error) {
console.error('Error:', error.message);
}
})();
Both methods allow you to work with rotating IP addresses, which lowers detection risk and makes the scraping process more efficient.
Conclusion
Integrating a proxy in Puppeteer isn’t difficult, but it makes a big difference. You don’t always need an advanced proxy configuration in place to avoid blocks, access geo-blocked content, and scale your automation, but if you’re after more complex or protected sites, you may need a combination of solutions.
A Puppeteer proxy setup with rotating proxies and proper proxy settings enables you to conduct more efficient web scraping, automation of repetitive web tasks, UI testing, and more.