How To Use Puppeteer Proxy With Authentication

1. Puppeteer page object's authenticate() method

There are a few options for using Headless Chrome to authenticate a proxy and using it in Puppeteer.

Puppeteer with a headless browser is found to be a very easy, yet effective tool for developers to automate numerous online tasks such as form filling, data scraping, and web page snapshots.

Puppeteer is nearly unbeatable when combined with a proxy; nevertheless, there may be some challenges when attempting to configure Puppetee appropriately to authorize a proxy that requires a login and password.

Using the Puppeteer page object’s authenticate() method:

Puppeteer has offered a built-in solution for authorizing a proxy with the authenticate() function for over three years. This is the most frequent way to accomplish it with vanilla Puppeteer nowadays.

const puppeteer = require('puppeteer');

const proxy = 'http://proxy.host.address:9000';
const username = 'your_proxy_username';
const password = 'your_proxy_password';

(async () => {
    // Pass proxy URL into the --proxy-server arg
    const browser = await puppeteer.launch({
        args: [`--proxy-server=${proxy}`],
    });

    const page = await browser.newPage()

    // Authenticate your proxy with the username and password defined above
    await page.authenticate({ username, password });

    await page.goto('https://www.google.com');

    await browser.close();
})();

2. Making use of the NPM package proxy-chain:

The proxy-chain NPM package is an open source tool created and maintained by Apify that takes a different route by allowing you to simply “anonymize” an authorized proxy.

This is accomplished by sending your proxy address along with authentication information to the proxyChain.anonymizeProxy function and then getting its value as the —proxy-server parameter when running Puppeteer.

const puppeteer = require('puppeteer');
const proxyChain = require('proxy-chain');

const proxy = 'http://your.proxy.address:9000';
const username = 'your_proxy_username';
const password = 'your_proxy_password';

(async () => {
    const originalUrl = `http://${username}:${password}@${proxy}`;

    // Return anonymized version of original URL - looks like http://127.0.0.1:16383
    const newUrl = await proxyChain.anonymizeProxy(originalUrl);

    const browser = await puppeteer.launch({
        args: [`--proxy-server=${newProxyUrl}`],
    });

    const page = await browser.newPage();

    await page.goto('https://www.google.com');

    await browser.close();

    // Close any pending connections
    await proxyChain.closeAnonymizedProxy(newProxyUrl, true);
})();

When utilizing this approach, it is vital to remember that after exiting the browser, you should use the closeAnonymizedProxy() function to forcefully close any pending connections.

This software handles both simple HTTP proxy forwarding and HTTP CONNECT tunneling to enable protocols like HTTPS and FTP. It also offers many more functionalities, thus it is interesting to explore for other applications.

Get Full Access To All Of Our Residential Proxies.

Residential Plans
Mobile Plans

Pay As You Go

1 GB
$15
  • $15 per GB
  • No Expiration
  • 170+ Countries
  • 24/7 Support
  • HTTP & SOCKS5
  • City & ISP Targeting
  • Unlimited Threads
  • Rollover bandwidth

Starter

3GB
$40
  • $13.3 per GB
  • No Expiration
  • 170+ Countries
  • 24/7 Support
  • HTTP & SOCKS5
  • City & ISP Targeting
  • Unlimited Threads
  • Rollover bandwidth

Hobby

15GB
$150
  • $10 per GB
  • No Expiration
  • 170+ Countries
  • 24/7 Support
  • HTTP & SOCKS5
  • City & ISP Targeting
  • Unlimited Threads
  • Rollover bandwidth

Startup

40GB
$300
  • $7.5 per GB
  • No Expiration
  • 170+ Countries
  • 24/7 Support
  • HTTP & SOCKS5
  • City & ISP Targeting
  • Unlimited Threads
  • Rollover bandwidth

Business

100GB
$600
  • $6 per GB
  • No Expiration
  • 170+ Countries
  • 24/7 Support
  • HTTP & SOCKS5
  • City & ISP Targeting
  • Unlimited Threads
  • Rollover bandwidth

Company

250GB
$1250
  • $5 per GB
  • No Expiration
  • 170+ Countries
  • 24/7 Support
  • HTTP & SOCKS5
  • City & ISP Targeting
  • Unlimited Threads
  • Rollover bandwidth

Pay As You Go

1 GB
$30
  • $30 per GB
  • No Expiration
  • 170+ Countries
  • 24/7 Support
  • HTTP & SOCKS5
  • City & ISP Targeting
  • Unlimited Threads
  • Rollover bandwidth

Mobile A

2GB
$60
  • $30 per GB
  • No Expiration
  • 170+ Countries
  • 24/7 Support
  • HTTP & SOCKS5
  • City & ISP Targeting
  • Unlimited Threads
  • Rollover bandwidth

Mobile S

5GB
$150
  • $30 per GB
  • No Expiration
  • 170+ Countries
  • 24/7 Support
  • HTTP & SOCKS5
  • City & ISP Targeting
  • Unlimited Threads
  • Rollover bandwidth

Mobile M

12GB
$300
  • $25 per GB
  • No Expiration
  • 170+ Countries
  • 24/7 Support
  • HTTP & SOCKS5
  • City & ISP Targeting
  • Unlimited Threads
  • Rollover bandwidth

Mobile L

30GB
$660
  • $22 per GB
  • No Expiration
  • 170+ Countries
  • 24/7 Support
  • HTTP & SOCKS5
  • City & ISP Targeting
  • Unlimited Threads
  • Rollover bandwidth

Mobile XL

85GB
$1530
  • $18 per GB
  • No Expiration
  • 170+ Countries
  • 24/7 Support
  • HTTP & SOCKS5
  • City & ISP Targeting
  • Unlimited Threads
  • Rollover bandwidth

See How Clients Are Using Residential Proxies.

Influencer Marketing

Digital stores and brands are using our residential and mobile proxies to extract valuable influencers across social platforms to increase sales.

Ad Verification

Advertisers use ProxyEmpire's network to sniff out potential ad fraud. They use granular targeting to see their ads on all devices and locations.

Sneaker Proxies

Catch the latest sneaker drops and cop them quick with fast residential proxies that go undetected by all sneaker brand sites. 

SEO Monitoring

Check your SERP performance with GEO-specific targeting and spy on the competition without them knowing using your own crawler.

ProxyEmpire
Works With All Of Your Favorite Tools.

Learning Center