diff --git a/fetch.bs b/fetch.bs index 9ccdbad7..7d78065b 100644 --- a/fetch.bs +++ b/fetch.bs @@ -2731,6 +2731,9 @@ functionality.
A fetch group holds an ordered list of fetch records. +
A fetch group holds an ordered list of +deferred fetch records. +
A fetch record has an associated request (a request). @@ -2739,16 +2742,103 @@ functionality. controller (a fetch controller or null). +
A deferred fetch record is a struct used to maintain state needed
+to invoke a fetch at a later time, e.g. when a Document
is unloaded or backgrounded. It
+has the following items:
+
+
When a fetch group is -terminated, for each associated -fetch record whose fetch record's -controller is non-null, and whose request's -done flag is unset or keepalive is false, -terminate the fetch record's -controller. +
When a fetch group fetchGroup is +terminated: + +
For each deferred fetch record + deferredRecord in fetchGroup's + deferred fetch records whose invoked is + false: + +
If deferredRecord's pending steps is not + null then abort deferredRecord's + pending steps. + +
For each associated fetch record record, + if record's controller is non-null and + record's request's done flag is unset or + keepalive is false, terminate record's + controller. +
When a fetch group fetchGroup is +activated: +for each deferred fetch record deferredRecord in +fetchGroup's deferred fetch records: + +
If deferredRecord's invoked is true then: +
If deferredRecord's invoked callback is not + null then call deferredRecord's invoked callback. + +
Remove deferredRecord from fetchGroup's + deferred fetch records. +
Otherwise, if deferredRecord's + pending steps is not null, then abort + deferredRecord's pending steps and set + deferredRecord's pending steps to null. +
When a fetch group fetchGroup is +deactivated: +
For each deferred fetch record deferredRecord in + fetchGroup's deferred fetch records whose + background timeout is not null: set deferredRecord's + pending steps to running the following steps in parallel: + +
Wait until deferredRecord's + background timeout have passed. + +
Queue a fetch task to run the following steps with + request's client's + global object: + +
+Deferred fetches allow callers to request that a fetch is invoked at the latest possible moment, +when a fetch group is terminated, or after a timeout after it is +deactivated. + +
To request a deferred fetch given a +request request and a null-or-{{DOMHighResTimeStamp}} +backgroundTimeout (default null): + +
Assert: request's client is an + environment settings object. + +
If request's body is not null then: + +
+For each deferred fetch record deferredRecord in + request's client's fetch group's + deferred fetch records: if deferredRecord's + request's body is not null and + deferredRecord's request's URL's + origin is same origin with request's URL's + origin, then increment totalScheduledDeferredBytesForOrigin by + deferredRecord's request's body's + length. + +
If totalScheduledDeferredBytesForOrigin is greater than 64 kilobytes, then + throw a {{QuotaExceededError}}. + +
Let deferredRecord be a new deferred fetch record whose + request is request. + +
Set deferredRecord's background timeout to + backgroundTimeout. + +
Append deferredRecord to request's + client's fetch group's + deferred fetch records. + +
Return deferredRecord. +
+ +dictionary DeferredRequestInit : RequestInit { + DOMHighResTimeStamp? backgroundTimeout; +}; + +partial interface mixin WindowOrWorkerGlobalScope { + [NewObject] Promise<Response> requestDeferredFetch(RequestInfo input, optional DeferredRequestInit init = {}); +}; ++ +
The
+requestDeferredFetch(input, init)
+method steps are:
+
+
Let promise be a new promise. + +
Let requestObject be the result of invoking the initial value of {{Request}} as + constructor with input and init as arguments. If that threw an exception, + reject promise with that exception and return promise. + +
If requestObject's signal is aborted, + then reject promise with requestObject's + signal's abort reason and return promise. + +
Let request be requestObject's request. + +
Let backgroundTimeout be null. + +
If init is given and init["backgroundTimeout
"]
+ exists then set backgroundTimeout to
+ init["backgroundTimeout
"].
+
+
If backgroundTimeout is not a {{DOMHighResTimeStamp}} then throw a {{TypeError}}. + +
Let deferredRecord be the result of calling + request a deferred fetch given request and backgroundTimeout. If that + threw an exception, reject promise with that exception and return + promise. + +
Set deferredRecord's invoke callback to + resolve promise. + +
Add the following abort steps to requestObject's + signal: remove deferredRecord from + request's client's fetch group's + deferred fetch records. +
data:
URLsFor an informative description of data:
URLs, see RFC 2397. This section replaces