How to make puppeteer work through socks5 proxy?

10,506

You can use page.authenticate() to provide the credentials for your proxy.

For example:

'use strict';

const puppeteer = require('puppeteer');

(async () => {
  const username = 'johndoe';
  const password = 'qwerty1';

  const browser = await puppeteer.launch({
    args: [
      '--proxy-server=socks5://proxyhost:8000',
    ],
  });

  const page = await browser.newPage();

  await page.authenticate({
    username,
    password,
  });

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

  await browser.close();
})();
Share:
10,506
Admin
Author by

Admin

Updated on June 13, 2022

Comments

  • Admin
    Admin about 2 years

    I bought a proxy server version of socsk5. In all manuals the same example

    const browser = await puppeteer.launch({
        headless: true,
        ignoreHTTPSErrors: true,
        defaultViewport: {...winSize},
        args: [
            '--proxy-server=socks5://proxyhost:8000',
            '--host-resolver-rules="MAP * ~NOTFOUND , EXCLUDE proxyhost"',
        ],
    })
    

    It does not specify a login password for this proxy and it clearly does not work

    If you specify this

    '--proxy-server=socks5://user:password@proxyhost:8000',
    

    it gives an error

    net::ERR_NO_SUPPORTED_PROXIES

    I tried with https://github.com/sjitech/proxy-login-automator build a bridge, but it did not work either.

    Prompt please

  • wSkc
    wSkc over 5 years
    Tested it with Tor ('--proxy-server=socks5://localhost:9050') and it worked flawlessly, thanks!
  • Gajus
    Gajus over 4 years
    Note that there are issues with proxy authentication when accessing HTTPS pages. github.com/puppeteer/puppeteer/issues/3253 You may want to try github.com/gajus/puppeteer-proxy