There is very little information available and I've tried multiple things but there isn't a way to know apparently from Puppeteer if the Window is different, for example if I move manually a "tab" (not in headless) outside, this creates a new Window, there is apparently no way to be aware of it or have a concept of Windows in Puppeteer, can someone shed the light on this?
I don't wish to open more Chromium instances as I want to stick with the same profile (without copy), I want to deal with multiple Window (not tabs).
Selenium has a clear way of handling that by using getWindowHandle
Currently, Puppeteer does not offer an API to do that. The underlying Chrome DevTools Protocol (CDP) might offer what you need. See Target.createTarget's newWindow parameter https://chromedevtools.github.io/devtools-protocol/tot/Target/#method-createTarget. It should be possible to get access to CDP and create a new window as following:
// pseudo-code, not tested if it works.
const client = await browser.target().createCDPSession();
const {targetId} = await client.send('Target.createTarget', { url: ..., newWindow: true });
const newTarget = await browser.waitForTarget(target => target.id === targetId);
It seems newWindow only has an effect in headful mode.
You can try puppeteer-cluster.
This is what the example looks like:
const { Cluster } = require('puppeteer-cluster');
(async () => {
const cluster = await Cluster.launch({
concurrency: Cluster.CONCURRENCY_CONTEXT,
maxConcurrency: 2,
});
await cluster.task(async ({ page, data: url }) => {
await page.goto(url);
const screen = await page.screenshot();
// Store screenshot, do something else
});
cluster.queue('http://www.google.com/');
cluster.queue('http://www.wikipedia.org/');
// many more pages
await cluster.idle();
await cluster.close();
})();