我正在尝试通过在浏览器控制台中运行一些javascript来自动执行某些操作。基本上,该脚本应该执行的操作是:
我的等待功能出现问题。我怀疑我的方法是错误的,但是由于某种原因,我在尝试调用它时遇到了错误。运行代码时,我两次收到此错误:
Uncaught (in promise) ReferenceError: waitForLoad is not defined ReferenceError: waitForLoad is not defined
我的代码:
button.click() // causes a loading animation div to appear
await waitForLoad();
console.log('Done waiting');
async function waitForLoad() {
let isWaiting = true;
while (isWaiting) {
await sleep(200);
isWaiting = nodeExists('div.load-animation');
}
}
function nodeExists(selector) {
return document.querySelectorAll(selector).length > 0;
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}