const PARES_CONCURENCY = 10; // сколько вкладок открываем за раз
runURLs([
'https://site.com/url1',
'https://site.com/url2',
'https://site.com/url3',
'https://site.com/url4'
// ...
]).then(() => console.log('Готово!'));
async function runURLs(urls) {
const browser = await puppeteer.launch();
const tasks = urls.map(url => async () => {
const page = await browser.newPage();
await page.goto(url);
// делаем что-то со страницей
await page.close();
});
const queue = tasks.slice(PARES_CONCURENCY)[Symbol.iterator]();
const runNextTask = () => {
const {value, done} = queue.next();
if(done) { return; }
return value().then(runNextTask);
};
await Promise.all(tasks.slice(0, PARES_CONCURENCY).map(task => task().then(runNextTask)));
await browser.close();
}