所以我每隔 x 秒在一个循环中运行 puppeteer bot (robot.js
) 以打开一个选项卡,从页面捕获一些数据并关闭选项卡....直到下一个循环
所以它工作正常,我可以在控制台中看到数据日志,但每次我都得到 p>
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/