wernerwernerwerner888
wernerwernerwerner888

Reputation: 35

Node.JS - Looping through arrays within an object

im a bit confused now. I want on puppeteer to start 5 browsers in the same time and give each of the browser his own socks5.

let socks = [array of socks]

Now i want to loop the array socks within every new browser i will start, but im not really sure how i can do it.

here is my code so far:

let socks = fs.readFileSync("socks.txt", "utf8").split("\r\n");

async function start() {
  const browser = await puppeteer.launch();
  const page = await brower.newPage();
}

for (var i = 0; i < 5; i++) {
  start(i, launchOption);
  wait(1000);
}

function wait(ms) {
  var start = new Date().getTime();
  var end = start;
  while (end < start + ms) {
    end = new Date().getTime();
  }
}

HOW can i loop through the socks array for each instance? Its not clear for me...thanks for any help!

Upvotes: 0

Views: 71

Answers (1)

rockTheWorld
rockTheWorld

Reputation: 501

you can pass is as argument to evaluate function

await page.evaluate((socks) => {
  console.log(socks); 
  socks.forEach((sock) => {
    /* your logic here */
  })
}, socks);

Upvotes: 1

Related Questions