13

How to set up a proxy with puppeteer? I tried the following:

(async () => {
    const browser = await puppeteer.launch({
        headless: false,
        args: [
            '--proxy-server=http://username:password@zproxy.luminati.io:22225'
        ]
    });
    const page = await browser.newPage();
    await page.goto('https://www.whatismyip.com/');
    await page.screenshot({ path: 'example.png' });

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

But it does not work and I get the message:

Error: net::ERR_NO_SUPPORTED_PROXIES at https://www.whatismyip.com/

on the console. How to use the proxy correctly?

I also tried the following:

const browser = await puppeteer.launch({
        headless: false,
        args: [
            '--proxy-server=zproxy.luminati.io:22225'
        ]
    });

 const page = await browser.newPage();

 page.authenticate({
        username: 'username',
        password: 'password'
 })

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

but the same result.

Jatt
  • 665
  • 2
  • 8
  • 20

4 Answers4

14
(async () => {
    // install proxy-chain  "npm i proxy-chain --save"
    const proxyChain = require('proxy-chain');

    // change username & password
    const oldProxyUrl = 'http://lum-customer-USERNAMEOFLUMINATI-zone-static-country-us:PASSWORDOFLUMINATI@zproxy.lum-superproxy.io:22225';
    const newProxyUrl = await proxyChain.anonymizeProxy(oldProxyUrl);

    const browser = await puppeteer.launch({
        headless: false,
        args: [
            '--no-sandbox',
            '--disable-setuid-sandbox',
            `--proxy-server=${newProxyUrl}`
        ]
    });

    const page = await browser.newPage();
    await page.goto('https://www.whatismyip.com/');
    await page.screenshot({ path: 'example.png' });

    await browser.close();
})();
Zilvia Smith
  • 511
  • 2
  • 5
  • 10
13

Chrome can not handle username and password in proxy URLs. The second option which uses page.authenticate should work

(async () => {
  const browser = await puppeteer.launch({
        headless: false,
        args: [
            '--proxy-server=zproxy.luminati.io:22225'
        ]
    });

 const page = await browser.newPage();

 // do not forget to put "await" before async functions
 await page.authenticate({        
        username: 'username',
        password: 'password'
 })

 await page.goto('https://www.whatismyip.com/');
 ...
})();
0x4a6f4672
  • 27,297
  • 17
  • 103
  • 140
  • Best Answer! the variant turned out to be working, unlike the variant with the proxy-chain library – MoloF Jan 12 '23 at 03:18
1

After removing the double quotes from the args worked fine for me.

https://github.com/puppeteer/puppeteer/issues/1074#issuecomment-359427293

Prabhat
  • 772
  • 1
  • 8
  • 22
mpcabete
  • 44
  • 4
0

Take care of quoting issues:

I had in Selenium (chromediver, same arguments):

"--proxy-server='http://1.1.1.1:8888'"

This is wrong! This gives me the reported error.

You need:

"--proxy-server=http://1.1.1.1:8888"