嗨,我正在尝试启动2个浏览器实例。
它假设只启动2个浏览器,但是却启动2个工作浏览器和1个空白浏览器?
下面是一张图片,显示我运行代码时发生的情况:
看到最左边的浏览器?它不应该打开。
这是我给p戏手的代码:
ipcMain.on('request-mainprocess-action', (event, arg) => {
// Puppeteer Cluster
(async () => {
const cluster = await Cluster.launch({
concurrency: Cluster.CONCURRENCY_CONTEXT,
maxConcurrency: 2,
puppeteerOptions: {
headless: false,
},
timeout: 120000,
});
await cluster.task(async ({ page, data: url }) => {
await page.goto(url, { waitUntil: 'load' });
// call function after done loading page
pageLoaded(await page.title());
// Will wait, so browsers dont close right after rendering
await new Promise(resolve => {
page.type('input[name=q]', arg)
});
});
cluster.execute(url);
cluster.execute(url);
await cluster.idle();
await cluster.close();
})();
});
我也将maxConcurrency
设置为2。
有人有什么想法吗?我对puppeteer还是很陌生,因为我刚刚从对硒的转换中受益。