我想在木偶操纵者遇到任何错误时关闭页面,有时会翻页我试图加载崩溃的页面并且它不会调用.close();
(async () => {
const page = await browser.newPage();
await page.setViewport({width: resWidth, height: resHeight});
await page.goto(d["entities"]["urls"][0]["expanded_url"], {timeout :90000});
await page.screenshot({path: './resimdata/'+d['id']+'.png' ,fullPage: true});
await page.close();
})();
答案 0 :(得分:0)
关于这个问题,木偶剧回购中存在一个问题/公关,这在类似情况下会有所帮助。
相关问题链接:https://github.com/GoogleChrome/puppeteer/issues/952
同时,你可以试试这个小小的黑客,如果PR版本在0.12+以上,我们不必担心以下代码。
(async() => {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
function handleClose(msg){
console.log(msg);
page.close();
browser.close();
process.exit(1);
}
process.on("uncaughtException", () => {
handleClose(`I crashed`);
});
process.on("unhandledRejection", () => {
handleClose(`I was rejected`);
});
await page.goto("chrome://crash");
})();
将输出如下内容,
▶ node app/app.js
I was rejected