错误消息: (节点:9644)UnhandledPromiseRejectionWarning:TimeoutError:导航超时超过3000毫秒在C:\ Users \ Samuel \ Desktop \ somnus-monitor \ back \ node_modules \ puppeteer \ lib \ cjs \ puppeteer \ common \ LifecycleWatcher.js:106:111在异步FrameManager.navigateFrame(C:\ Users \ Samuel \ Desktop \ somnus-monitor \ back \ node_modules \ puppeteer \ lib \ cjs \ puppeteer \ common \ FrameManager.js:90:21)在异步Frame.goto(C:\ Users \ Samuel \ Desktop \ somnus-monitor \ back \ node_modules \ puppeteer \ lib \ cjs \ puppeteer \ common \ FrameManager.js:416:16)在异步Page.goto(C:\ Users \ Samuel \ Desktop \ somnus-monitor \ back \ node_modules \ puppeteer \ lib \ cjs \ puppeteer \ common \ Page.js:789:16)在异步C:\ Users \ Samuel \ Desktop \ somnus-monitor \ back \ index.js:103:9(使用`node --trace-warnings ...`来显示警告的产生位置)(节点:9644)UnhandledPromiseRejectionWarning:未处理的承诺被拒绝.该错误是由于在没有catch块的情况下抛出异步函数而引起的,或者是由于拒绝了未使用.catch()处理的诺言而引起的.要在未处理的承诺拒绝时终止节点进程,请使用CLI标志`--unhandled-rejections = strict`(请参阅https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode).(拒绝ID:1)(节点:9644)[DEP0018] DeprecationWarning:已弃用未处理的承诺拒绝.将来,未处理的承诺拒绝将以非零退出代码终止Node.js进程. 解决方案这里似乎有不必要的 waitForNavigation 调用.由于您已经等到页面加载完毕,因此等待从未发生的其他导航将导致超时.重新添加下面的注释行以重现您的问题. const puppeteer = require("puppeteer");(异步()=> {const browser = await puppeteer.launch({无头:假,defaultViewport:null,});尝试 {const [page] =等待browser.pages();等待page.setViewport({width:1920,height:1080});await page.goto("https://www.xtract.io/",{waitUntil:"load"}));//await page.waitForNavigation({waitUntil:" load"});;//这将超时等待page.screenshot({fullPage:是的,路径:"temporal.png",});}抓(err){console.error(err);}等待browser.close();})(); 顺便说一句,我不认为您打算将多个对象传递给 puppeteer.launch .只需将所有设置作为第二个参数添加到单个对象即可,如上所示.I've been trying to use Puppeteer to scrape a website, but when I try to obtain the screenshot it never loads it either goes to a TimeoutError or just never finishes.(async () => { try{ const navegador = await puppeteer.launch({headless: false},{defaultViewport: null}); const pagina = await navegador.newPage(); await pagina.setDefaultNavigationTimeout(3000); await pagina.goto(urlSitio, {waitUntil: 'load'}); await pagina.setViewport({width: 1920, height: 1080}); await pagina.waitForNavigation({waitUntil: 'load'}); await pagina.screenshot({ fullPage: true, path: `temporales/temporal.png` }); await navegador.close(); }catch(err){ console.log(err); } })();I've tried to set await pagina.setDefaultNavigationTimeout(3000); to 0 and multiple other numbers.I've tried removing headless: false.I've also tried putting all the different options forawait pagina.waitForNavigation({waitUntil: 'load'});The website example I'm using is https://www.xtract.io/Error message:(node:9644) UnhandledPromiseRejectionWarning: TimeoutError: Navigation timeout of 3000 ms exceeded at C:\Users\Samuel\Desktop\somnus-monitor\back\node_modules\puppeteer\lib\cjs\puppeteer\common\LifecycleWatcher.js:106:111 at async FrameManager.navigateFrame (C:\Users\Samuel\Desktop\somnus-monitor\back\node_modules\puppeteer\lib\cjs\puppeteer\common\FrameManager.js:90:21) at async Frame.goto (C:\Users\Samuel\Desktop\somnus-monitor\back\node_modules\puppeteer\lib\cjs\puppeteer\common\FrameManager.js:416:16) at async Page.goto (C:\Users\Samuel\Desktop\somnus-monitor\back\node_modules\puppeteer\lib\cjs\puppeteer\common\Page.js:789:16) at async C:\Users\Samuel\Desktop\somnus-monitor\back\index.js:103:9(Use `node --trace-warnings ...` to show where the warning was created)(node:9644) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)(node:9644) [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. 解决方案 There appears to be an unnecessary waitForNavigation call here. Since you already waited until page load, waiting for another navigation that never occurs is going to cause a timeout. Re-add the commented-out line below to reproduce your problem.const puppeteer = require("puppeteer");(async () => { const browser = await puppeteer.launch({ headless: false, defaultViewport: null, }); try { const [page] = await browser.pages(); await page.setViewport({width: 1920, height: 1080}); await page.goto("https://www.xtract.io/", {waitUntil: "load"}); //await page.waitForNavigation({waitUntil: "load"}); // this will timeout await page.screenshot({ fullPage: true, path: "temporal.png", }); } catch (err) { console.error(err); } await browser.close();})();As an aside, I don't think you meant to pass multiple objects to puppeteer.launch. Just add all of the settings to a single object as the second argument as shown above. 这篇关于木偶永远不会完全加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-11 09:13