Skip to main content
Version: 23.5.0

Page.waitForResponse() 方法

¥Page.waitForResponse() method

签名

¥Signature

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

参数

¥Parameters

范围

类型

描述

urlOrPredicate

字符串| AwaitablePredicate<HTTPResponse>

要等待的 URL 或谓词。

options

WaitTimeoutOptions

(可选的)可选等待参数

Returns:

Promise<HTTPResponse>

解析为匹配响应的 Promise。

¥Promise which resolves to the matched response.

备注

¥Remarks

可选参数有:

¥Optional Parameter 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 firstResponse = await page.waitForResponse(
'https://example.com/resource'
);
const finalResponse = await page.waitForResponse(
response =>
response.url() === 'https://example.com' && response.status() === 200
);
const finalResponse = await page.waitForResponse(async response => {
return (await response.text()).includes('<html>');
});
return finalResponse.ok();