我收到未处理的Promise拒绝警告。我正在与pupetteer一起浏览网页。代码可以完美运行,但是我认为错误处理能力很差
const puppeteer = require('puppeteer');
const LOGIN_PG = 'https://website.com'
puppeteer.launch({headless: false}, {defaultViewport: null}).then(async browser => {
const page = await browser.newPage();
const navigationPromise = page.waitForNavigation()
await page.goto(LOGIN_PG, {waitUntil: "networkidle2"})
await page.focus('input[id=loginform-login]')
await page.keyboard.type('username')
await page.focus('input[id=loginform-password]')
await page.keyboard.type(password)
await page.click('button[type=submit]')
for (i = 0; i < 30; i++) {
await navigationPromise
try {
await page.waitForSelector('a[class]',{timeout: 60000})
await page.click('a[class]',{timeout: 60000})
}
catch (e){
console.log (e)
if (TimeoutError == false){
break
}
}
console.log('check number ' + i)
while (i == 10 || i == 20) {
console.log('refresh')
await page.reload({waitUntil: "load"})
break
}
}
console.log('object found')
await page.waitForSelector('input[class]')
await page.click('input[class]')
});