-
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
- Loading branch information
1 parent
eaf6fb2
commit 97ab4b4
Showing
3 changed files
with
40 additions
and
5 deletions.
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}))); | ||
}); |
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