Published on

How to use HTTP or HTTPS Proxy in Puppeteer

Authors

When automating things or web scraping, you might need to use a proxy to bypass and perform certain actions.

Let's see how to use HTTP proxy in the Puppeteer script

Dependency

When using a proxy, we need to take care of a lot of things like authentication.

To avoid doing everything manually, we'll be using proxy-chain

npm install proxy-chain

Also, we'll need the proxy address (along with its authentication) which you can get it from your proxy provider.

Snippet

import puppeteer from 'puppeteer';
import proxyChain from 'proxy-chain';


const proxyUrl = 'http://username:password@host:port';

const newProxyUrl = await proxyChain.anonymizeProxy(proxyUrl);

const browser = await puppeteer.launch({
    headless:false,
    args: [`--proxy-server=${newProxyUrl}`]
});
// reset of the code ...

Happy using proxies!