Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deferred fetching #1647

Open
wants to merge 102 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
49f9e1e
Deferred fetching
noamr May 2, 2023
a9d0b24
nits
noamr May 4, 2023
3eb155d
Update fetch.bs
noamr May 8, 2023
f78e5e0
Move sections around
noamr May 8, 2023
30fcf5e
Rename to fetchLater and backgroundTimeout
noamr May 8, 2023
a38a86f
Fix hierarchy
noamr May 8, 2023
b602f6b
Restructure to expose a boolean instead of a promise
noamr Jun 11, 2023
b4bae0e
nit
noamr Jun 11, 2023
9a0180e
or/and
noamr Jun 18, 2023
84c794b
Remove spurious promise
noamr Jun 29, 2023
9e234b4
Rename backgrounded
noamr Jun 29, 2023
e301c55
Throw a few more errors
noamr Jul 4, 2023
dabea52
Always set keepalive
noamr Jul 5, 2023
25efd01
Nits
noamr Aug 20, 2023
a0dc674
Remove atomics, leave thread safety to implementation
noamr Aug 20, 2023
742e55b
Throw RangeError when backgroundTimeout is negative
noamr Aug 23, 2023
5b75fa2
Refactor out backgroundTimeout, use activationTimeout
noamr Sep 19, 2023
e34decd
Throw on ReadableStream
noamr Sep 19, 2023
a05a071
Fix grammar
noamr Sep 19, 2023
110cb8d
Several editorial changes, renamed to activationDeadline
noamr Oct 2, 2023
aa68e95
Handle CR nits
noamr Oct 3, 2023
a77984d
Remove h2
noamr Oct 3, 2023
cb46ef2
Bring back line break
noamr Oct 3, 2023
34bf293
nit
noamr Oct 3, 2023
308cb1b
nit
noamr Oct 3, 2023
ba49a99
nit
noamr Oct 3, 2023
64d5a73
- Rename activationDeadline to activateAfter
noamr Oct 9, 2023
cf5503c
Throw a NotAllowedError for 3p envs
noamr Oct 25, 2023
d356198
Add top-level + per-sink quota
noamr Mar 12, 2024
5475990
Check permissions policy
noamr Mar 12, 2024
842f23c
Narrow scope to Window
noamr Mar 13, 2024
4009bcf
Remove existing NotAllowedError
noamr Mar 13, 2024
a1f2cc7
Fix null-body issues
noamr Mar 13, 2024
3ed435f
Revise based on nits
noamr Mar 25, 2024
693f569
Use correct dfn
noamr Mar 25, 2024
92b605d
Remove spurious whitespace
noamr Mar 25, 2024
afca31d
Use $
noamr Mar 25, 2024
5da508e
Use new quota algorithm
noamr Apr 11, 2024
7e101e4
nits
noamr Apr 11, 2024
dc22a76
Include url+headers in the quota
noamr Apr 26, 2024
02637d2
Allow 16kb (UA-specific) even for 3p contexts
noamr Sep 5, 2024
ff93d28
Update for new quota policy
noamr Oct 24, 2024
8147f0d
Fix <ol>
noamr Oct 24, 2024
d49ac64
Only decrement for cross-origin
noamr Oct 24, 2024
0ea54ef
Apply permission policy
noamr Oct 24, 2024
7bbed76
nits
noamr Oct 24, 2024
2512346
refactor
noamr Oct 28, 2024
45f18de
Refactor quota based on new explainer
noamr Oct 28, 2024
fe47282
nits
noamr Oct 28, 2024
305b3a0
Clarify permission policy
noamr Oct 31, 2024
54cc33c
Remove wrong use of reporting origin
noamr Oct 31, 2024
322a0dc
typo
noamr Oct 31, 2024
1e2f858
Sort out some quota logic
noamr Nov 20, 2024
c740fd1
Sort out some quota logic
noamr Nov 20, 2024
417dd32
Fix container
noamr Dec 3, 2024
2e24866
Extract 'total request length' to a function
noamr Dec 3, 2024
9c3a799
Don't compute relatives twice
noamr Dec 3, 2024
29c422f
Refactor loop
noamr Dec 4, 2024
af751d9
Fix indents
noamr Dec 4, 2024
2c84b7d
Fix indent
noamr Dec 4, 2024
793a29c
Fix list
noamr Dec 4, 2024
8998e3d
Remove spurious <li>
noamr Dec 4, 2024
c7d70dc
Tersify loop
noamr Dec 4, 2024
2548d06
Refactor algorithm, simplify a lot
noamr Dec 8, 2024
a984713
Use constants
noamr Dec 9, 2024
91e2736
Refactor quota algorithm
noamr Dec 9, 2024
b91401a
Follow up on PR feedback
noamr Dec 9, 2024
043abc7
linkify activateAfter
noamr Dec 9, 2024
ed638f2
Add examples
noamr Dec 9, 2024
3fa4984
Throw {{TypeError}}
noamr Dec 9, 2024
3e724c4
nits
noamr Dec 10, 2024
6500061
nits
noamr Dec 10, 2024
5e287d9
Fix reserve algo
noamr Dec 10, 2024
b72c664
Add note about conds
noamr Dec 10, 2024
66a69ac
Add detailed example for iframe quota
noamr Dec 10, 2024
4745716
granted
noamr Dec 11, 2024
7a24661
Lots of fixes
noamr Dec 11, 2024
c82df4b
Turn quota example into a tree
noamr Dec 11, 2024
664ba39
Some more nits
noamr Dec 11, 2024
cb85aad
Clarify containers in algo
noamr Dec 11, 2024
e7d90fb
Make algo a bit more readable
noamr Dec 11, 2024
ef6c324
nits
noamr Dec 12, 2024
4c07c9c
Update algorithm to only share quota for direct relatives
noamr Dec 15, 2024
d97b105
Editorial pass
noamr Dec 16, 2024
c228737
Change initial quota computation to a switch statement
noamr Dec 16, 2024
54d9aea
More editorial
noamr Dec 16, 2024
1870b69
Bring back <ol>
noamr Dec 16, 2024
88ae669
Nits
noamr Jan 6, 2025
7856454
Improve switch statement
noamr Jan 6, 2025
6432b5d
Update note
noamr Jan 7, 2025
c345eb8
Fix issue with reserve algo
noamr Jan 7, 2025
1ca8615
Clarify notes
noamr Jan 8, 2025
b610d58
nits
noamr Jan 13, 2025
efe0730
Use 'otherwise'
noamr Jan 16, 2025
303dc5a
Keep record on both document and control document
noamr Jan 21, 2025
04c5a3f
nit
noamr Jan 21, 2025
5aa1df5
Try to fix build
noamr Jan 21, 2025
27cec10
Keep records in subframe
noamr Jan 22, 2025
5be8047
Simplify quota
noamr Jan 22, 2025
5225029
Revert "Simplify quota"
noamr Jan 23, 2025
850bb46
Reapply "Simplify quota"
noamr Jan 23, 2025
139351f
Fix algo
noamr Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revise based on nits
  • Loading branch information
noamr committed Jan 21, 2025
commit 3ed435f5d7f612dedaeacca6327170e9b84dacfa
91 changes: 45 additions & 46 deletions fetch.bs
noamr marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2732,20 +2732,22 @@ functionality.
<p>Each <a>environment settings object</a> has an associated
<dfn export id=concept-fetch-group for=fetch>fetch group</dfn>.

<p>A <a for=fetch>fetch group</a> holds an ordered list of
<dfn lt="fetch record" export for="fetch group" id=concept-fetch-record>fetch records</dfn>.
<p>A <a for=fetch>fetch group</a> has an associated
<dfn lt="fetch record" export for="fetch group" id=concept-fetch-record>fetch records</dfn>,
a <a for=/>list</a> of <a for="/" data-lt="fetch record">fetch records</a>.

<p>A <a for=fetch>fetch group</a> holds a <a for=/>list</a> of
<dfn export for="fetch group" id=concept-defer=fetch-record>deferred fetch records</dfn>.
<p>A <a for=fetch>fetch group</a> has an associated
<dfn export for="fetch group" id=concept-defer=fetch-record>deferred fetch records</dfn>,
a <a for=/>list</a> of <a data-lt="deferred fetch record">deferred fetch records</a>.

<p>A <a for="fetch group">fetch record</a> has an associated
<dfn export for="fetch record" id=concept-fetch-record-request>request</dfn> (a
<a for=/>request</a>).
<p>A <dfn export>fetch record</dfn> is a [=struct=]. It has the following items:

<p>A <a for="fetch group">fetch record</a> has an associated
<dfn export for="fetch record" id=concept-fetch-record-fetch>controller</dfn> (a
<a for=/>fetch controller</a> or null).
<dl>
<dt><dfn export for="fetch record">request</dfn>
<dd>A <a for=/>request</a>.

<dt><dfn export for="fetch record">controller</dfn>
<dd>A <a for=/>fetch controller</a> or null.

<hr>

Expand All @@ -2763,8 +2765,8 @@ not <a for=Document>fully active</a>. It has the following <a for=struct>items</

<p class=note>This value can be modified <a>in parallel</a>. There could be a race condition where
the <code>Document</code> object's <a for=/>event loop</a> might read it as
"<code>deferred</code>" at the same time that it is changed to "<code>activated</code>". UAs can
mitigate this race condition in an <a>implementation-defined</a> manner.
"<code>deferred</code>" at the same time that it is changed to "<code>activated</code>". User
agents can mitigate this race condition in an <a>implementation-defined</a> manner.
</dl>


Expand Down Expand Up @@ -6753,9 +6755,9 @@ agent's <a>CORS-preflight cache</a> for which there is a <a>cache entry match</a
<h3 id=deferred-fetching>Deferred fetching</h3>

<p>Deferred fetches allow callers to request that a fetch is invoked at the latest possible moment,
noamr marked this conversation as resolved.
Show resolved Hide resolved
i.e. when a <a>fetch group</a> is <a for="fetch group">terminated</a>, or after a timeout.
i.e., when a <a>fetch group</a> is <a for="fetch group">terminated</a>, or after a timeout.

<div algorithm="request-a-deferred-fetch">
<div algorithm>
<p>To <dfn>request a deferred fetch</dfn> given a
<a for=/>request</a> <var>request</var> and a null or {{DOMHighResTimeStamp}}
<var>activateAfter</var> (default null):
Expand All @@ -6770,14 +6772,14 @@ i.e. when a <a>fetch group</a> is <a for="fetch group">terminated</a>, or after
<a>HTTP(S) scheme</a>, then throw a {{TypeError}}.

<li><p>If <var>request</var>'s <a for=request>URL</a> is not a
[=potentially trustworthy url=], then throw a "{{SecurityError}}" {{DOMException}}.
<a>potentially trustworthy url</a>, then throw a "{{SecurityError}}" {{DOMException}}.

<li><p>If the result of calling <a>is feature enabled in document for origin?</a> given
<li><p>If the result of calling <a>is feature enabled in document for origin?</a> given
"<code>deferred-fetch</code>", <var>document</var>, and <var>request</var>'s
<a for=request>origin</a> is <code>Disabled</code>, then throw a {{NotAllowedError}}.

<li>
<p>If <var>request</var>'s <a for=request>body</a> is not null then:
<p>If <var>request</var>'s <a for=request>body</a> is non-null then:

<ol>
<li><p>If <var>request</var>'s
Expand All @@ -6801,10 +6803,10 @@ i.e. when a <a>fetch group</a> is <a for="fetch group">terminated</a>, or after
<a for=Document>inclusive descendant navigables</a>:

noamr marked this conversation as resolved.
Show resolved Hide resolved
<p class=note>This algorithm asserts that this deferred fetch doesn't exceed two quotas: one for
the top-level document (640kb), and one for the reporting origin (64kb). The larger quota ensures
that the top-level {{Document}} and its subresources don't continue using an unlimited amount of
bandwidth after being destroyed. The smaller quota ensures that a single reporting sink doesn't
reserve the whole quota to itself.
the top-level document (640 kibibytes), and one for the reporting origin (64 kibibytes). The
larger quota ensures that the top-level {{Document}} and its subresources don't continue using
an unlimited amount of bandwidth after being destroyed. The smaller quota ensures that a single
reporting sink doesn't reserve the whole quota to itself.

<ol>
<li>
Expand All @@ -6820,14 +6822,14 @@ i.e. when a <a>fetch group</a> is <a for="fetch group">terminated</a>, or after
<li><p>Increment <var>totalScheduledDeferredBytesForTopLevelDocument</var> by <var>length</var>.

<li><p>If <var>totalScheduledDeferredBytesForTopLevelDocument</var> is greater than 640
kilobytes, then throw a "{{QuotaExceededError}}" {{DOMException}}.
kibibytes, then throw a "{{QuotaExceededError}}" {{DOMException}}.

<li><p>If <var>deferredRecord</var>'s <a for="deferred fetch record">request</a>'s
<a for=request>URL</a>'s <a for=url>origin</a> is <a>same origin</a> with
<var>request</var>'s <a for=request>origin</a>, then increment
<var>totalScheduledDeferredBytesForOrigin</var> by <var>length</var>.

<li><p>If <var>totalScheduledDeferredBytesForOrigin</var> is greater than 64 kilobytes, then
<li><p>If <var>totalScheduledDeferredBytesForOrigin</var> is greater than 64 kibibytes, then
throw a "{{QuotaExceededError}}" {{DOMException}}.
</ol>
</li>
Expand All @@ -6847,16 +6849,16 @@ i.e. when a <a>fetch group</a> is <a for="fetch group">terminated</a>, or after
<a for="fetch group">deferred fetch records</a>.

<li>
<p>If <var>activateAfter</var> is not null, then run the following steps <a>in parallel</a>:</p>
<p>If <var>activateAfter</var> is non-null, then run the following steps <a>in parallel</a>:</p>

<ol>
<li><p>The user agent should wait until <var>activateAfter</var> milliseconds have passed,
or until the user agent has a reason to believe that it is about to lose the opportunity to
execute scripts, e.g. when the browser is moved to the background, or when <var>request</var>'s
execute scripts, e.g., when the browser is moved to the background, or when <var>request</var>'s
<a for=request>client</a> is a <code>Document</code> that had a "<code>hidden</code>"
<a for=Document>visibility state</a> for a long period of time.

<li><p>The user agent may wait for a further <a>implementation-defined</a> <a>duration</a>, e.g.
<li><p>The user agent may wait for a further <a>implementation-defined</a> <a>duration</a>, e.g.,
in order to batch several requests together or to wait until <a for=request>keepalive</a>
requests are complete.

Expand All @@ -6868,7 +6870,7 @@ i.e. when a <a>fetch group</a> is <a for="fetch group">terminated</a>, or after
</ol>
</div>
noamr marked this conversation as resolved.
Show resolved Hide resolved

<div algorithm="process-deferred-fetches">
<div algorithm>
<p>To <dfn export>process deferred fetches</dfn> given a <a>fetch group</a> <var>fetchGroup</var>:

<ol>
Expand All @@ -6884,7 +6886,7 @@ i.e. when a <a>fetch group</a> is <a for="fetch group">terminated</a>, or after
</ol>
</div>

<div algorithm="process-a-deferred-fetch">
<div algorithm>
<p>To <dfn>process a deferred fetch</dfn> <var>deferredRecord</var>:
<ol>
<li><p>If <var>deferredRecord</var>'s <a for="deferred fetch record">invoke state</a> is not
Expand All @@ -6899,6 +6901,7 @@ i.e. when a <a>fetch group</a> is <a for="fetch group">terminated</a>, or after
</div>



<h2 id=fetch-api>Fetch API</h2>

<p class=note>The <a method><code>fetch()</code></a> method is relatively low-level API for
Expand Down Expand Up @@ -8626,6 +8629,20 @@ otherwise false.
partial interface mixin WindowOrWorkerGlobalScope {
[NewObject] Promise&lt;Response> fetch(RequestInfo input, optional RequestInit init = {});
};


dictionary DeferredRequestInit : RequestInit {
DOMHighResTimeStamp activateAfter;
};

[Exposed=Window]
interface FetchLaterResult {
readonly attribute boolean activated;
};

partial interface mixin Window {
[NewObject] FetchLaterResult fetchLater(RequestInfo input, optional DeferredRequestInit init = {});
};
</pre>

<div algorithm>
Expand Down Expand Up @@ -8759,22 +8776,6 @@ with a <var>promise</var>, <var>request</var>, <var>responseObject</var>, and an
</ol>
</div>

<pre class=idl>

dictionary DeferredRequestInit : RequestInit {
DOMHighResTimeStamp activateAfter;
};

[Exposed=Window]
interface FetchLaterResult {
readonly attribute boolean activated;
};

partial interface mixin Window {
[NewObject] FetchLaterResult fetchLater(RequestInfo input, optional DeferredRequestInit init = {});
};
</pre>

<p>A {{FetchLaterResult}} has an associated <a>deferred fetch record</a>
noamr marked this conversation as resolved.
Show resolved Hide resolved
<dfn for=FetchLaterResult>deferred record</dfn>.

Expand Down Expand Up @@ -8804,8 +8805,6 @@ method steps are:
<a for=map>exists</a>, then set <var>activateAfter</var> to
<var>init</var>["<code>activateAfter</code>"].

<li><p>If <var>activateAfter</var> is not a {{DOMHighResTimeStamp}}, then throw a {{TypeError}}.

<li><p>If <var>activateAfter</var> is less than 0, then throw a {{RangeError}}.

<li><p>Let <var>deferredRecord</var> be the result of calling
Expand Down