javascript - puppeteer 调试 : finding which line is cuzing the error

标签 javascript puppeteer

所以我每隔 x 秒在一个循环中运行 puppeteer bot (robot.js) 以打开一个选项卡,从页面捕获一些数据并关闭选项卡....直到下一个循环

所以它工作正常,我可以在控制台中看到数据日志,但每次我都得到

opening page  1 -> ok 
    (node:11867) UnhandledPromiseRejectionWarning: Error: Protocol error (Runtime.callFunctionOn): Session closed. Most likely the page has been closed.
        at CDPSession.send (/home/hostname/domains/example.com/robot/node_modules/puppeteer/lib/Connection.js:189:29)
        at ExecutionContext.evaluateHandle (/home/hostname/domains/example.com/robot/node_modules/puppeteer/lib/ExecutionContext.js:89:75)
        at ElementHandle.$ (/home/hostname/domains/example.com/robot/node_modules/puppeteer/lib/ElementHandle.js:272:50)
        at Frame.$ (/home/hostname/domains/example.com/robot/node_modules/puppeteer/lib/FrameManager.js:357:34)
    (node:11867) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
    (node:11867) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

opening page  2 -> ok 
bot done successfully ... closing tab for the next loop 

如您所见,我收到一条错误消息,告诉我 session 已在进程中间关闭....奇怪的是循环已成功完成并且可以正常工作

我不知道这是什么原因,为什么

所以这是我的问题....有什么方法可以获取更多信息,了解是哪一行引起了这个错误(或与之有任何关系),以及在 robot.js 中发生了什么?

我在错误堆栈中看到的所有内容都是引用 puppeteer 内部模块,这在这种情况下对我来说几乎没用

最佳答案

引入了 Puppeteer 1.9.0 async stacks - 错误现在应将您指向代码中的实际行。

关于javascript - puppeteer 调试 : finding which line is cuzing the error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52628176/

相关文章:

javascript - 如何在任何网络浏览器中运行 Puppeteer 代码?

javascript - 循环内的“page.evaluate()”(在 Puppeteer 中)返回相同的值

javascript - jQuery datepicker 无法在 Codeigniter 和 Bootstrap 模式表单中工作

javascript - 获取 JS(mouseover,mouseleave)以在 html 文档中的图像上显示不同的文本

javascript - 为什么这个小书签不能转换为用户脚本?

javascript - 根据页面加载时选择的单选按钮显示某些字段

javascript - HTML 元素从节点列表中消失

node.js - 如何限制使用 puppeteer 渲染的资源

javascript - 监视(mutationobserver)puppeteer 中元素的文本更改

google-chrome-headless - Puppeteer 安装有错误