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:
- Input all profile information in .json file
- Have code launch a unique instance for every profile in the list
- 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
Post a Comment