Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make puppeteer work through socks5 proxy?

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

like image 644
Chupurnov Avatar asked Sep 12 '18 09:09

Chupurnov


1 Answers

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();
})();
like image 149
Grant Miller Avatar answered Oct 05 '22 14:10

Grant Miller