javascript – pupeteer debuging:找到哪条线路正在酝酿错误

所以我每隔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 

正如你所看到我得到一个错误,告诉我会话已经在进程中间关闭….奇怪的是,循环是成功完整的,没有问题的工作

我不知道这是什么以及为什么

所以这里是我的问题….有没有办法获得更多关于什么线路(或与之有关)这个错误的信息,以及在robot.js中发生了什么?

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

解决方法:

Puppeteer 1.9.0引入了async stacks – 错误现在应该指向代码中的实际行.

上一篇:javascript – 按类名收集元素,然后单击每个元素 – Puppeteer


下一篇:javascript – 从Iframe抓取文本