跳至主要內容
版本:23.11.1

Page.waitForRequest() 方法

簽名

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

參數

參數

類型

描述

urlOrPredicate

string | AwaitablePredicate<HTTPRequest>

要等待的 URL 或述詞

options

WaitTimeoutOptions

(可選) 可選的等待參數

返回

Promise<HTTPRequest>

解析為匹配請求的 Promise

備註

可選的等待參數有:

  • timeout:最長等待時間(以毫秒為單位),預設為 30 秒,傳遞 0 可停用逾時。可以使用 Page.setDefaultTimeout() 方法變更預設值。

範例

const firstRequest = await page.waitForRequest('https://example.com/resource');
const finalRequest = await page.waitForRequest(
request => request.url() === 'https://example.com',
);
return finalRequest.response()?.ok();