In puppeteer , when i want to use console.log from evaluate , it triggers me an error
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
page.on('console', msg => console.log('PAGE LOG:', ...msg.args));
await page.goto('http://google.com', {waitUntil: 'load'});
await page.evaluate(async() => console.log('url is ${location.href}'));
browser.close();
})();
(node:70544) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: undefined is not iterable (node:70544) [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.
你知道如何处理吗?
最佳答案
msg.args
值未定义,因此当您尝试使用扩展运算符 (...msg.args
) 时,它会失败。
要么记录msg.args
,要么将其包装在空/未定义的检查中
关于javascript - puppeteer : console. 登录评估触发器错误 "Unhandled promise rejection",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46918489/