FetchEvent: handled プロパティ
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2022年9月.
メモ: この機能はサービスワーカー内でのみ利用可能です。
handled
は FetchEvent
インターフェイスのプロパティで、このイベントがフェッチアルゴリズムによって処理されたかどうかを示すプロミスを返します。このプロパティは、ブラウザーがレスポンスを消費した後にコードを実行することができ、通常は waitUntil()
メソッドと共に使用します。
値
イベントが処理されるまでは待機し、イベントが処理されると履行される Promise
です。
例
js
addEventListener("fetch", (event) => { event.respondWith( (async function () { const response = await doCalculateAResponse(event.request); event.waitUntil( (async function () { await doSomeAsyncStuff(); // オプション // イベントがブラウザーによって消費されるのを待つ await event.handled; return doFinalStuff(); // イベントが消費された後に後始末 })(), ); return response; })(), ); });
仕様書
Specification |
---|
Service Workers> # dom-fetchevent-handled> |
ブラウザーの互換性
Loading…