如何使用puppeteer的page.evaluate()获取所有网络请求?

时间:2020-01-13 14:55:19

标签: javascript puppeteer

有没有办法让page.evaluate()等待直到至少500毫秒没有网络请求(例如page.goto()等待networkidle0)?

例如:

await page.evaluate('window.location = "https://example.com"');
// listen to the network requests until there are no requests fired for at least 500 ms

1 个答案:

答案 0 :(得分:0)

waitUntil仅在导航上下文中才有意义。如果您想为waitUntil本身提供evaluate()选项,那么答案是否定的。但是,如果您使用evaluate()触发导航,则可以使用waitForNavigation()

await page.evaluate(() => window.location = "https://example.com")
await page.waitForNavigation({waitUntil: 'networkidle0'});