Puppeteer launch multiple instances with unique data?

I've been trying to get puppeteer to launch a unique instance for every profile stored in a .json file. This is because currently I am stuck creating a new folder with all my code and a unique .json file for every account/instance I want to run. I'd prefer if I could just store all my info in 1 .json file and then have my code launch a unique instance for each profile.

Goal:

  1. Input all profile information in .json file
  2. Have code launch a unique instance for every profile in the list
  3. Every unique instance should only be using the profile code

Example: Puppeter instance 1 launch with profile 1, puppeteer instance 2 launch with profile 2, etc.

Example of settings.json

[
{
    "email": "email1@gmail.com"
},
{
    "email": "email2@gmail.com"
},
{
    "email": "email3@gmail.com"
}
]

Example of main.js

const fs = require('fs');
const puppeteer = require('puppeteer');

const profile = JSON.parse(fs.readFileSync('./settings.json'));

var id = 0

while (id <= 2) {
    emailInfo = profile[id].email;
    console.log(emailInfo)
    botRun()
    id++;
}

function botRun() {
    (async () => {
        const browser = await puppeteer.launch();
        const page = await browser.newPage();
        await page.waitForTimeout(500)
        console.log('function ' + emailInfo) //pretend this is page.type --> it would result in 'email3@gmail.com' for all instances since this is what the var is now but I want it to stay with the info in the loop

        await browser.close();
      })();
}

Obviously this is horrendously wrong since emailInfo var will update therefore resulting in puppeteer applying the latest value. Is there any way I can make each puppeteer instance stick with the unique data?



from Recent Questions - Stack Overflow https://ift.tt/39x5ddE
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations