如果页面未重新加载,waitForNavigation会导致超时

时间:2019-06-19 15:46:28

标签: javascript puppeteer

我正在跑步:

    await page.waitForNavigation()

但是如果页面没有重新加载,我超时:

    TimeoutError: Navigation Timeout Exceeded: 30000ms exceeded

我不确定hte页面是否要重新加载,因此我需要将await page.waitForNavigation包装在仅在页面重新加载后才能运行的内容中。有什么建议吗?

2 个答案:

答案 0 :(得分:0)

我不确定我是否理解正确,但是如果您不确定何时进行导航,请尝试

await page.waitForNavigation({timeout: 0})

它会等待而不会超时

答案 1 :(得分:0)

使用javascript错误处理基础知识可能是方法:

Try{  
  await page.waitForNavigation()  
}  
catch(error){  
  //"do something if you got an error in the Try"  
}

doc:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch
或:https://www.w3schools.com/js/js_errors.asp