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: + +

+
request +
A request + +
background timeout (default null) +
Null or a duration + +
pending steps (default null) +
invoked callback (default null) +
Null or an algortihm accepting nothing + +
invoked (default false) +
A boolean +
+ +
-

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: + +

    +
  1. +

    For each deferred fetch record + deferredRecord in fetchGroup's + deferred fetch records whose invoked is + false: + +

      +
    1. If deferredRecord's pending steps is not + null then abort deferredRecord's + pending steps. + +

    2. fetch deferredRecord's request. +

    + +
  2. 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: + +

    +
  1. +

    If deferredRecord's invoked is true then: +

      +
    1. If deferredRecord's invoked callback is not + null then call deferredRecord's invoked callback. + +

    2. Remove deferredRecord from fetchGroup's + deferred fetch records. +

    + +
  2. 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: +

    +
  1. +

    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: + +

      +
    1. Wait until deferredRecord's + background timeout have passed. + +

    2. +

      Queue a fetch task to run the following steps with + request's client's + global object: + +

        +
      1. Fetch record's request. + +

      2. Set deferredRecord invoked to true. +

      +
    3. +
    +
  2. +

Resolving domains

@@ -8640,6 +8730,117 @@ fetch("https://www.example.com/") +

Deferred fetching

+ +

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. + +

Requesting a deferred fetch

+ +
+

To request a deferred fetch given a +request request and a null-or-{{DOMHighResTimeStamp}} +backgroundTimeout (default null): + +

    +
  1. Assert: request's client is an + environment settings object. + +

  2. Let totalScheduledDeferredBytesForOrigin be 0. + +
  3. +

    If request's body is not null then: + +

      +
    1. If request's + body's length is null, then throw a {{TypeError}}. + +

    2. Set totalScheduledDeferredBytesForOrigin to request's + body's length. +

    +
  4. + +
  5. 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. + +

  6. If totalScheduledDeferredBytesForOrigin is greater than 64 kilobytes, then + throw a {{QuotaExceededError}}. + +

  7. Let deferredRecord be a new deferred fetch record whose + request is request. + +

  8. Set deferredRecord's background timeout to + backgroundTimeout. + +

  9. Append deferredRecord to request's + client's fetch group's + deferred fetch records. + +

  10. Return deferredRecord. +

+
+ +

RequestDeferredFetch method

+ +
+
+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: + +

    +
  1. Let promise be a new promise. + +

  2. 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. + +

  3. If requestObject's signal is aborted, + then reject promise with requestObject's + signal's abort reason and return promise. + +

  4. Let request be requestObject's request. + +

  5. Let backgroundTimeout be null. + +

  6. If init is given and init["backgroundTimeout"] + exists then set backgroundTimeout to + init["backgroundTimeout"]. + +

  7. If backgroundTimeout is not a {{DOMHighResTimeStamp}} then throw a {{TypeError}}. + +

  8. 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. + +

  9. Set deferredRecord's invoke callback to + resolve promise. + +

  10. Add the following abort steps to requestObject's + signal: remove deferredRecord from + request's client's fetch group's + deferred fetch records. +

+

data: URLs

For an informative description of data: URLs, see RFC 2397. This section replaces