-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Background Fetch] Throw DOMException for responseReady on abort.
According to the spec, responseReady in BackgroundFetchRecord should throw an AbortError DOMException if the fetch was abandoned. https://wicg.github.io/background-fetch/#create-record-objects (2.4.3) Change-Id: Ieadf278acd061e05b8822014d0934f050fcac702 Reviewed-on: https://chromium-review.googlesource.com/c/1283692 Commit-Queue: Rayan Kanso <rayankans@chromium.org> Reviewed-by: Peter Beverloo <peter@chromium.org> Cr-Commit-Position: refs/heads/master@{#600769}
- Loading branch information
1 parent
8ca1dc4
commit 067c5e2
Showing
2 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
importScripts('sw-helpers.js'); | ||
|
||
async function getFetchResult(record) { | ||
try { | ||
await record.responseReady; | ||
} catch (e) { | ||
return { | ||
response: false, | ||
name: e.name, | ||
}; | ||
} | ||
|
||
return { | ||
response: true, | ||
}; | ||
} | ||
self.addEventListener('backgroundfetchabort', event => { | ||
event.waitUntil( | ||
event.registration.matchAll() | ||
.then(records => | ||
Promise.all(records.map(record => getFetchResult(record)))) | ||
.then(results => sendMessageToDocument({results}))); | ||
}); |