Puppeteer Proxy with Authorization How To

โฌ‡๏ธ Experience our high-end residential proxies for just $1.97

Puppeteer Proxy

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.

TL;DR

For developers seeking effective online task automation, using Puppeteer with proxies is an unbeatable option. Our article provides comprehensive guidance on how to configure Puppeteer to authorize a proxy with login and password. A common method is using Puppeteer’s page object’s authenticate() method. Here, your proxy URL is passed into the –proxy-server argument, the browser is launched and your page is authenticated via the username and password.

Another approach involves leveraging the NPM package proxy-chain for anonymizing an authorized proxy. Authentication details are sent to the proxyChain.anonymizeProxy function, which returns a value for use as the –proxy-server parameter when running Puppeteer. Please note the necessity of using the closeAnonymizedProxy() function to forcefully close any pending connections on browser exit. The proxy-chain software additionally supports simple HTTP proxy forwarding and HTTP CONNECT tunneling, thus enabling protocols such as HTTPS and FTP. Explore these functionalities for robustย proxy solutions.

You May Also Like:

What Is a Soundcloud Proxy?

What Is a Soundcloud Proxy?

You're scrolling through SoundCloud, but suddenly, you hit a wall โ€” geo-restrictions. That's where SoundCloud proxies come in....

Flexible Pricing Plan

logo purple proxyempire

Our state-of-the-art proxies.

Experience online freedom with our unrivaled web proxy solutions. Pioneering in breaking through geo-barriers, CAPTCHAs, and IP blocks, our premium, ethically-sourced network boasts a vast pool of IPs, expansive location choices, high success rate, and versatile pricing. Advance your digital journey with us.

๐Ÿ˜๏ธ Rotating Residential Proxies
  • 9M+ Premium Residential IPs
  • ย 170+ Countries
    Every residential IP in our network corresponds to an actual desktop device with a precise geographical location. Our residential proxies are unparalleled in terms of speed, boasting a success rate of 99.56%, and can be used for a wide range of different use cases. You can use Country, Region, City and ISP targeting for our rotating residential proxies.

See our Rotating Residential Proxies

๐Ÿ“ Static Residential Proxies
  • 20+ Countries
    Buy a dedicated static residential IP from one of the 20+ countries that we offer proxies in. Keep the same IP for a month or longer, while benefiting from their fast speed and stability.

See our Static Residential Proxies

๐Ÿ“ณ Rotating Mobile Proxies
  • 5M+ Premium Residential IPs
  • ย 170+ Countries
    Access millions of clean mobile IPs with precise targeting including Country, Region, City, and Mobile Carrier. Leave IP Blocks and Captchas in the past and browse the web freely with our 4G & 5G Proxies today.

See our Mobile Proxies

๐Ÿ“ฑ Dedicated Mobile Proxies
  • 5+ Countries
  • 50+ Locations
    Get your own dedicated mobile proxy in one of our supported locations, with unlimited bandwidth and unlimited IP changes on demand. A great choice when you need a small number of mobile IPs and a lot of proxy bandwidth.

See our 4G & 5G Proxies

๐ŸŒ Rotating Datacenter Proxies
  • 70,000+ Premium IPs
  • ย 10+ Countries
    On a budget and need to do some simple scraping tasks? Our datacenter proxies are the perfect fit! Get started with as little as $2

See our Datacenter Proxies

proxy locations

9.5M+ rotating IPs

99% uptime - high speed

99.9% uptime.

dedicated support team

24/7 Dedicated Support.

fair price

Fair Pricing.

โžก๏ธ 20% Discount code for All Proxy Plans:ย  “proxyautumn20”