Skip to main content
Web Scraping

How to Set Up a Proxy in Puppeteer

Learn how to set up a proxy in Puppeteer, handle authentication, and use rotating proxies to avoid getting blocked.

ZenezenZenezen
·3 min read

AI Summary

Get a summary of this page using your preferred AI assistant.

How to Set Up a Proxy in Puppeteer

When you're running Puppeteer for web scraping or automation, your requests go out from the same IP every time. Sites with bot detection will catch on quickly and block you before you get far. Adding a proxy routes your traffic through a different IP, keeping your sessions alive and your data flowing.

In this article, we'll explore how to set up a proxy in Puppeteer, the different ways to configure it, and how to pair it with rotating proxies for large-scale scraping.


How to Set Up a Proxy in Puppeteer

How to Set Up a Proxy in Puppeteer

Setting up a proxy in Puppeteer is straightforward. You pass the proxy server as an argument in the launch options:

JavaScript
1const browser = await puppeteer.launch({
2  args: ['--proxy-server=http://your-proxy-ip:port']
3});

If your proxy requires authentication, handle credentials at the page level:

JavaScript
1await page.authenticate({
2  username: 'your-username',
3  password: 'your-password'
4});

Every request the browser makes will go through that proxy until you close the instance. For any serious scraping, though, you'll need rotating proxies.

Also Read: How to Scrape LinkedIn Jobs


How to Use Rotating Proxies with Puppeteer

How to Use Rotating Proxies with Puppeteer

A static proxy gets blocked fast on repeated requests. Rotating proxies fix this by assigning a new IP to each session, so the target site never sees the same source twice.

The cleanest approach is to open a new browser instance per session. Most providers give you a single endpoint that handles rotation automatically:

JavaScript
1const browser = await puppeteer.launch({
2  args: ['--proxy-server=http://rotating-proxy-endpoint:port']
3});
4
5const page = await browser.newPage();
6
7await page.authenticate({
8  username: 'your-username',
9  password: 'your-password'
10});
11
12await page.goto('https://target-site.com');
13await browser.close();

Closing the browser after each session forces a fresh connection and triggers a new IP from the pool. Residential proxies work best here since they're assigned by real ISPs and are nearly impossible for sites to flag. Residential proxies start at $1.75/GB with no subscription required.


How to Test Your Proxy Setup

How to Test Your Proxy Setup

Before running your scraper, it's worth confirming your proxy is actually working. The quickest way is to make a request to an IP-checking service and log the response:

JavaScript
1const browser = await puppeteer.launch({
2  args: ['--proxy-server=http://your-proxy-ip:port']
3});
4
5const page = await browser.newPage();
6
7await page.authenticate({
8  username: 'your-username',
9  password: 'your-password'
10});
11
12await page.goto('https://api.ipify.org?format=json');
13const content = await page.content();
14console.log(content);
15await browser.close();

If the IP in the response is different from your real IP, the proxy is working. If it matches your real IP, something in your configuration is off. Check that the proxy URL and port are correct and that your credentials are being passed at the page level, not in the launch URL.

For rotating proxies, run this a few times and check that the IP changes between sessions. If you're getting the same IP every time, the browser instance isn't being closed and reopened between requests.

Also Read: Best Residential Proxy Providers


Final Words

Setting up a proxy in Puppeteer takes just a few lines of code. Match your proxy type to your target, close browser instances between sessions, and pace your requests. Proxyon's residential proxies start at $1.75/GB with no subscription required, deposit $5, and start scraping in minutes at Proxyon.

Related Posts

Everything you need to extract web data reliably.

Residential from $1.75/GB, datacenter from $1.50/IP, plus mobile, ISP, and IPv6. Pay-as-you-go. No subscriptions, no contracts. Deposit $5 and start today.

Get Started

Get 100MB free · No credit card required · Instant access