开始打开网页 2021-2-22T09:32:19.799Z [verbose] 访问 url 次数 1 2021-12-22T09:32:32.340Z [verbose] 标签页 3 2021-12-22T09:33:09.763Z [verbose] 浏览器错误 { Error: Protocol error (Runtime.callFunctionOn): Target closed. at Promise (/code/node_modules/puppeteer/lib/Connection.js:183:56) at Promise (null:null:null) at send (/code/node_modules/puppeteer/lib/Connection.js:182:12) at _evaluateInternal (/code/node_modules/puppeteer/lib/ExecutionContext.js:107:44) at evaluateHandle (/code/node_modules/puppeteer/lib/ExecutionContext.js:57:17) at (/code/node_modules/puppeteer/lib/helper.js:112:23) at rerun (/code/node_modules/puppeteer/lib/DOMWorld.js:570:65) at _tickCallback (internal/process/next_tick.js:68:7) message: 'Protocol error (Runtime.callFunctionOn): Target closed.' } 2021-12-22T09:33:09.764Z [error] (node:23) UnhandledPromiseRejectionWarning: Error: Protocol error (Network.getCookies): Session closed. Most likely the page has been closed. at send (/code/node_modules/puppeteer/lib/Connection.js:180:29) at cookies (/code/node_modules/puppeteer/lib/Page.js:382:32) at (/code/node_modules/puppeteer/lib/helper.js:112:23) at Promise (/code/aicard-event.js:367:28) 2021-12-22T09:33:09.764Z [error] (node:23) 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: 2) 2021-12-22T09:33:09.764Z [error] (node:23) [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. FC Invoke End RequestId: , Error: Function timed out after 120 seconds (maxMemoryUsage: 0MB) 我这块在第一次打开页面的时候waitForFunction报错提示超时,于是我会再重试一次,这个时候waitForFunction就会报Protocol error (Runtime.callFunctionOn): Target closed.,这个问题我十次里面会遇到一两次,想问问这个是为啥啊,我中间 url 啥的都没改,就只是重新再 page.goto 一次,为什么会提示这个错误呢。
还有一个问题,这个是我这个方法的结构,我上面waitForFunction报错之后进入 catch ,在这里面获取 cookie ,但是目标关闭导致失败,这个时候什么会提示后面的错误,我想问问我这个不是写了 reject 吗,完了在调用toPDF时也写了.then().catch(),请问这个正确的写法该是怎样的呢
function toPDF() { return new Promise((resolve, reject) => { for (let i = 0; i < 2; i++) { try { //打开页面生成 pdf resolve() } catch (e) { // 获取 cookie } } reject(error) }) } 