【发布时间】:2021-09-25 18:28:45
【问题描述】:
我不明白为什么下面的代码抱怨check() 不是一个函数。当我用目标函数使它成为一个对象时,它再次抱怨没有找到这样的函数。我已经尝试解决这个问题 6 个小时了。任何帮助将不胜感激...
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto('https://bet254.com');
const check=await page.evaluate(() => {
return function () {
try {
return document.getElementsByClassName("header-buttons")[0].childNodes[0].textContent.trim() !== "Login";
} catch (e) {
console.log(e);
return false;
}
}
});
if (check()) {
console.log("Logged in already!");
} else {}
以下是错误:-
(node:9632) UnhandledPromiseRejectionWarning: TypeError: check is not a function
at D:\void\js_\node_puppeteer\entry.js:19:9
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:9632) 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:9632) [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.
【问题讨论】:
标签: javascript node.js async-await puppeteer headless