メインコンテンツにスキップ
バージョン: 22.5.0

Page.waitForResponse() メソッド

シグネチャ:

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

パラメータ

パラメータ説明
urlOrPredicatestring | AwaitablePredicate<HTTPResponse>待機するURLまたは述語。
optionsWaitTimeoutOptions(オプション) オプションの待機パラメータ

戻り値

Promise<HTTPResponse>

一致するレスポンスで解決されるPromise。

備考

オプションパラメータ

  • timeout: 最大待機時間(ミリ秒)。デフォルトは30秒。タイムアウトを無効にするには0を渡します。デフォルト値はPage.setDefaultTimeout()メソッドを使用して変更できます。

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();