【发布时间】:2021-11-22 18:56:09
【问题描述】:
我点击触发 http 请求的按钮 我希望能够在请求完成后关闭页面。
示例: Await page.click(一些触发http请求的按钮)
我试过了:Await page.waitForLoadState() 随着“负载”和“网络空闲”,它没有工作。 加载页面在请求完成时关闭,网络空闲等待超时。
我希望能够在后台等待所有的 xhr 请求完成
【问题讨论】:
标签: playwright
我点击触发 http 请求的按钮 我希望能够在请求完成后关闭页面。
示例: Await page.click(一些触发http请求的按钮)
我试过了:Await page.waitForLoadState() 随着“负载”和“网络空闲”,它没有工作。 加载页面在请求完成时关闭,网络空闲等待超时。
我希望能够在后台等待所有的 xhr 请求完成
【问题讨论】:
标签: playwright
这是一个网络限制,您不能等待所有请求完成。什么是所有请求?如果每 50ms 有一个请求怎么办?
在您的情况下,您可能希望等待特定请求:
// Note that Promise.all prevents a race condition
// between clicking and waiting for the response.
const [response] = await Promise.all([
// Waits for the next response with the specified url
page.waitForResponse('https://example.com/resource'),
// Triggers the response
page.click('button.triggers-response'),
]);
// Alternative way with a predicate.
const [response] = await Promise.all([
// Waits for the next response matching some conditions
page.waitForResponse(response => response.url() === 'https://example.com' && response.status() === 200),
// Triggers the response
page.click('button.triggers-response'),
]);
请看这里:https://playwright.dev/docs/api/class-page#page-wait-for-response
【讨论】: