question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

perBrowserOptions - Proxy Question?

See original GitHub issue

Hi,

I am trying to create an application that will run multiple instances of puppeteer, each instance will have its own proxy. The new “perBrowserOptions” is good but how can I set the proxy based on the Taskfunction that has been queued when using “CONCURRENCY_BROWSER”?

Here is an example to try and explain what i mean…

`const {Cluster} = require(‘puppeteer-cluster’);

(async ()=>{

const proxies = [];

//Create the cluster
const cluster = await Cluster.launch({
    concurrency: Cluster.CONCURRENCY_BROWSER,
    maxConcurrency: 4,
    // puppeteerOptions : {
    //     headless : false,
    //     args : [
    //         '--no-sandbox',
    //         '--disable-setuid-sandbox',
    //         '--disable-infobars',
    //         '--window-position=0,0',
    //         '--ignore-certifcate-errors',
    //         '--ignore-certifcate-errors-spki-list',
    //         `--proxy-server=${proxies.shift()}`
    //     ]
    // },
    //Something like this would be nice
    browserLaunchedOption:()=>{
        //return options for browser
        return {
            headless : false,
            args : [
                '--no-sandbox',
                '--disable-setuid-sandbox',
                '--disable-infobars',
                '--window-position=0,0',
                '--ignore-certifcate-errors',
                '--ignore-certifcate-errors-spki-list',
                `--proxy-server=${proxies.shift()}`
            ]
        }
    }
});


const loginFBWithProxyTask = async ({page,data})=> {


    proxies.push(data.proxy.ip);
    
    //Somehow need to set the proxy here... from data.proxy.ip
    //Proxy must match account
    
    await page.authenticate({
        username: data.proxy.user,
        password: data.proxy.pass
    });

    await page.goto("http://facebook.com", {waitUntil: "domcontentloaded"});
    //await page.type()
    //perform login etc....
};


//check DB every 30 sec
setInterval(function () {
    
    //fetch some accounts from a db
    
    const accounts = [  //returned from db just for example
        {
            fb_username : "Joe Blogs",
            fb_password : "pass",
            proxy : {
                ip : "51.91.195.74:29842",
                user : "proxyuser",
                pass : "password"
            }
        },
        {
            fb_username : "Jame Smith",
            fb_password : "pass",
            proxy : {
                ip : "21.21.195.24:29842",
                user : "myproxyuser",
                pass : "myproxypass"
            }
        },
        {
            fb_username : "Mary Poppins",
            fb_password : "pass",
            proxy : {
                ip : "21.21.295.24:29842",
                user : "myproxyuser",
                pass : "myproxypass"
            }
        }];
    
    //QUEUE UP Tasks to perform perBrowser
    for (const account in accounts) {
        
        cluster.queue(account,loginFBWithProxyTask);
    }
    
},30000);

})();`

I just can’t work out how i can set the proxy per browser launch to match the account that is fetched/queued…

Hope some of that made sense, thanks!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
lazybottercommented, Apr 19, 2020

Im not sure, would something like cluster.queueWithBrowserOptions(data,taskFunction,browserOptions) work?

Or add another prop to cluster.queue(data,taskFunction,browserOptions) then if “CONCURRENCY_BROWSER” is used, “pupeteerOptions” can be defined for each task in the queue.

Thanks

0reactions
gud3commented, Oct 4, 2022

+1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Help in the use of puppeteer-cluster #277 - GitHub
Hello, I'm practicing with headless browser and I plan to make a little viewerbot. The goal would be to be able to put...
Read more >
I can't use a rotating IP proxy in my puppeteer cluster script
I am trying to run this code with multiple address ips but I think I put the proxy code in the wrong place...
Read more >
Creating a new browser profile and attaching a proxy in ...
In this video we show you how to create your first browser profile in Incogniton. The only thing you need to do is...
Read more >
puppeteer-cluster - bytemeta
How use proxy? · Help in the use of puppeteer-cluster · Make a live viewer bot - Questions · No error thrown on...
Read more >
Puppeteer Proxy Integration With Oxylabs
Proxy integration with Puppeteer, a Node.js library, is simple. Find out how to integrate Oxylabs' Residential Proxies in this easy-to-understand tutorial.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found