Puppeteer not loading page - NodeJs

Viewed 776

Here is a simple program on puppeteer:

const puppeteer = require('puppeteer');

    async function run() {
       const browser = await puppeteer.launch({
            headless: false,
            
            args:[ `--proxy-server=104.233.50.38:3199`]
        });
        ;
        const page = await browser.newPage();
        await page.authenticate({
                username: 'myusername',
                password: 'mypassword'
            })
            await page.goto('https://google.com')
    };

run();

Note: I have tried similar with over 10 proxies and none of them are working in puppeteer

The credentials are exactly what is provided to me, I have checked multiple times.

This is what I get:

Puppeteer not loading page

Now again , this is the console of the page:

Puppeteer error loading page console view

Why is this happening?

I checked the addresses and username, password multiple times. There is no other error message except this.

2 Answers

It seems that page.authenticate is not working for me either,instead you can use page.setExtraHTTPHeaders

async function run() {
const browser = await puppeteer.launch({
    ignoreHTTPSErrors: true, 
    args: ['--proxy-server=104.233.50.38:3199']
});
const page = await browser.newPage();
await page.setExtraHTTPHeaders
({'Proxy-Authorization': 'Basic ' + Buffer.from('username:password').toString('base64'),
});
};
 
run();

You can use puppeteer-page-proxy, it offers username and password auth very easily. It also supports http, https, socks4 and socks5 proxies. https://github.com/Cuadrix/puppeteer-page-proxy

You can define the proxy this way:

const proxy = 'http://login:pass@IP:Port';

or

const proxy = 'socks5://IP:Port';

Then you can use it per request:

const useProxy = require('puppeteer-page-proxy');
await page.setRequestInterception(true);
page.on('request', req => {
    useProxy(req, proxy);
});
Related