Search code examples
javascripttypescriptweb-scrapingwebpuppeteer

How to connect to a proxy server with puppeteer?


I am trying now for a while to connect to a proxy with puppeteer. I am using the latest version and I couldn't get it to connect after endless tries. I searched, I documented, I read but I don't even know what to do anymore.

This is what I tried yet:

 browser = await puppeteer.launch({
            headless: false,
            defaultViewport: null,
            args: ['--start-fullscreen', 'proxyServer=ip:port'],
        })

or instead of proxyServer I tried with "--proxy-server" but still does not work. Or I also tried doing it like this:

await browser!.createIncognitoBrowserContext({
            proxyServer: 'http://ip:port',
        })

Still nothing. Puppeteer version is 21.1.1 Also I am using proxies which do not need username and password so that is not the problem.


Solution

  • You would add the args like this:

    args: [
      '--start-fullscreen',
      `--proxy-server=http://${host}:${port}`
    ]
    

    and to authenticate you would do:

    await page.authenticate({ username, password })