apify / proxy-chain

Node.js implementation of a proxy server (think Squid) with support for SSL, authentication and upstream proxy chaining.
https://www.npmjs.com/package/proxy-chain
Apache License 2.0
804 stars 138 forks source link

proxy-chain and puppeteer in same process do not send username and password proxy-authorization #524

Closed gawsoftpl closed 8 months ago

gawsoftpl commented 8 months ago

When I run proxy-chain and puppeteer in same process puppeteer do not send username and password to proxy-chain. There is not proxy-authorization in headers

Username is for decide which production proxy to run (by username i select real proxy server). This is very strange. When I run this in same project puppeteer do not send proxy-authorization header. But when I run proxy chain in outside of node_modules (other project and other process), everything works fine.

puppeteer

# Create browser
browser = await puppeteer.launch([
  `--proxy-server=127.0.0.1:5050`,
]);

# Page
await this.page.authenticate({
      username: 'residential',
      password: 'empty',
});

await this.page.goto('https://example.com');
const data = await this.page.content();

Proxy chain server

new ProxyChain.Server({
        port: 5050,
        verbose: false,
        prepareRequestFunction: ({
          request,
          username,
          password,
        }) => {
          console.log(request.url, 'u:', username, password);

          const proxyUrl = generateProxyUrl(request, username);

          if (!proxyUrl)
            console.log('Error. Return empty proxy url in proxy chain');
          return {
            upstreamProxyUrl: proxyUrl,
          };
        },
      });
gawsoftpl commented 8 months ago

I found resolution I have to add:

requestAuthentication: username.length == 0,

first proxy server require authentication, after that puppeteer send username and password