Skip to main content
Version: 23.10.1

Page.waitForRequest() 方法

¥Page.waitForRequest() method

签名

¥Signature

class Page {
waitForRequest(
urlOrPredicate: string | AwaitablePredicate<HTTPRequest>,
options?: WaitTimeoutOptions,
): Promise<HTTPRequest>;
}

参数

¥Parameters

范围

类型

描述

urlOrPredicate

字符串| AwaitablePredicate<HTTPRequest>

要等待的 URL 或谓词

options

WaitTimeoutOptions

(可选的)可选等待参数

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 to 30 seconds, pass 0 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();