Page.waitForRequest() 方法
¥Page.waitForRequest() method
签名
¥Signature
class Page {
waitForRequest(
urlOrPredicate: string | AwaitablePredicate<HTTPRequest>,
options?: WaitTimeoutOptions,
): Promise<HTTPRequest>;
}
参数
¥Parameters
范围 | 类型 | 描述 |
---|---|---|
urlOrPredicate | 要等待的 URL 或谓词 | |
options | (可选的)可选等待参数 |
Returns:
Promise<HTTPRequest>
解析匹配请求的 Promise
¥Promise which resolves to the matched request
备注
¥Remarks
可选的等待参数有:
¥Optional Waiting Parameters have:
-
timeout
:最大等待时间(以毫秒为单位),默认为30
秒,通过0
禁用超时。可以使用 Page.setDefaultTimeout() 方法更改默认值。¥
timeout
: Maximum wait time in milliseconds, defaults to30
seconds, pass0
to disable the timeout. The default value can be changed by using the Page.setDefaultTimeout() method.
示例
¥Example
const firstRequest = await page.waitForRequest('https://example.com/resource');
const finalRequest = await page.waitForRequest(
request => request.url() === 'https://example.com',
);
return finalRequest.response()?.ok();