gajus / puppeteer-proxy

Proxies Puppeteer Page requests.
Other
197 stars 24 forks source link

Support for socks5 proxy with authentication #7

Closed Nik-Novak closed 4 years ago

Nik-Novak commented 4 years ago

I tried to connect to a socks5 proxy with the following proxyUrl property: socks5://username:password@192.168.1.121:1080

But it failed with (node:9488) UnhandledPromiseRejectionWarning: TimeoutError: Navigation timeout of 30000 ms exceeded

Note this proxy works perfectly as a socks5 proxy in other libraries.

I think if you could add support for authentication and socks5 a lot more people might use this tool

gajus commented 4 years ago

Simply pass socks-proxy-agent instance to agent, e.g.

import puppeteer from 'puppeteer';
import {
  proxyRequest,
} from 'puppeteer-proxy';
import {
  SocksProxyAgent,
} from 'socks-proxy-agent';

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  const agent = {
    http: new SocksProxyAgent('socks5://'),
    https: new SocksProxyAgent('socks5://'),
  };

  await page.setRequestInterception(true);

  page.on('request', async (request) => {
    await proxyRequest({
      agent,
      page,
      proxyUrl: 'http://127.0.0.1:3000',
      request,
    });
  });

  await page.goto('http://gajus.com');
})();

Refer to https://github.com/sindresorhus/got#agent

dannyokec commented 2 years ago

Please this code doesn't show where to append authentication to the sock5 proxy (username and password), it doesn't show where to input the address, I tried setting the address at the http and https socks 5 url link but none seemed to work

sunnyd24 commented 2 years ago

Using with authentication details doesn't seem to work with other projects such as FlareSolverr.

See my issue report on FlareSolverr Github which points to Puppeteer Proxy limitation that causes this issue.

Any ideas and suggest reopening issue?