我的环境
我的问题是:
我有一个for...of
循环,可以使用伪造者访问3000多个网址。我使用puppeteer.connect
到wsEndpoint
,所以我可以重用一个浏览器实例。每次访问后我都会断开连接并关闭标签。
page.goto
立即打开URL,page.goto
每个网址使用2-3次重试,page.goto
每个网址使用5-8次重试,TimeoutError: Navigation timeout of 30000 ms exceeded
。[我检查了Windows任务管理器,实现了数百个Chromium实例在后台运行,并且每个实例使用80-90MB的内存以及1-2%的CPU。
问题
如何杀死已经与browser.disconnect
断开连接的Chromium实例?
示例脚本
const puppeteer = require('puppeteer') const urlArray = require('./urls.json') // contains 3000+ urls in an array async function fn() { const browser = await puppeteer.launch({ headless: true }) const browserWSEndpoint = await browser.wsEndpoint() for (const url of urlArray) { try { const browser2 = await puppeteer.connect({ browserWSEndpoint }) const page2 = await browser2.newPage() await page2.goto(url) // in my original code it's also wrapped in a retry function // doing cool things with the DOM await page2.goto('about:blank') // because of you: https://github.com/puppeteer/puppeteer/issues/1490 await page2.close() await browser2.disconnect() } catch (e) { console.error(e) } } await browser.close() } fn()
错误
通常的操纵up超时错误。
TimeoutError: Navigation timeout of 30000 ms exceeded
at C:\[...]\node_modules\puppeteer\lib\LifecycleWatcher.js:100:111
-- ASYNC --
at Frame.<anonymous> (C:\[...]\node_modules\puppeteer\lib\helper.js:94:19)
at Page.goto (C:\[...]\node_modules\puppeteer\lib\Page.js:476:53)
at Page.<anonymous> (C:\[...]\node_modules\puppeteer\lib\helper.js:95:27)
at example (C:\[...]\example.js:13:18)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
name: 'TimeoutError'
}
我的环境Puppeteer版本:3.1.0平台/操作系统版本:Windows 10 Node.js版本:12.16.1我的问题是:我有一个for ... of循环,可以使用puppeteer访问3000多个URL。我使用puppeteer.connect ...
最后,我能够通过在启动时添加--single-process
和--no-zygote
args来获得所需的结果(+需要--no-sandbox
)。