简体   繁体   中英

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!

you can pass is as argument to evaluate function

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM