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

Use sourceDocument if set for prefetch lookup #267

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

@github-actions
Copy link

Preview:

Copy link
Collaborator

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, but what do you think about unconditionally using sourceDocument, instead of only using it for prerendering?

For example, I think that would be necessary to make <a href="prefetched.html" target="_blank"> work, which is desirable.

@hiroshige-g
Copy link
Author

unconditionally using sourceDocument

Perhaps this makes sense.
See https://chromium-review.googlesource.com/c/chromium/src/+/4422475 for behavior changes.

Yesterday I and @nyaxt discussed not to make this generalization because this would dissappear after #266, but the updates after that are:

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 13, 2023
…gation

Bug: 1432886, WICG/nav-speculation#267
Change-Id: I4098347c42f45188811700fcc8d7925bcc3c4162
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 13, 2023
Bug: 1432886, WICG/nav-speculation#267
Change-Id: I4098347c42f45188811700fcc8d7925bcc3c4162
@hiroshige-g
Copy link
Author

Uploaded a commit that uses sourceDocument if set, but as also I added as inline issue comments in the commit, I'm not so sure how to plumb sourceDocument in some cases -- maybe we just don't plumb sourceDocument and fallback to navigable's active document instead?

Copy link
Collaborator

@domenic domenic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall strategy looks good, just some ideas on how to make it cleaner.

prefetch.bs Outdated Show resolved Hide resolved
prefetch.bs Outdated
@@ -432,6 +436,8 @@ Update all creation sites to supply an empty string, except for any in this docu
1. Let |coopEnforcementResult| be the result of [=creating a cross-origin opener policy enforcement result for navigation=] given <var ignore>navigable</var>'s [=navigable/active document=] and <var ignore>entry</var>'s [=session history entry/document state=]'s [=document state/initiator origin=].
1. Set <var ignore>navigationParams</var> to the result of [=creating navigation params by fetching=] given |request|, <var ignore>entry</var>, |coopEnforcementResult|, <var ignore>navigable</var>, <var ignore>sourceSnapshotParams</var>, <var ignore>targetSnapshotParams</var>, <var ignore>cspNavigationType</var>, <var ignore>navigationId</var>, and <var ignore>navTimingType</var>.

The |sourceDocument| argument should be plumbed from <a spec=HTML>navigate</a>'s |sourceDocument| and <a spec=HTML>traverse the history by a delta</a>'s |sourceDocument|.
<p class="issue">How about other callers, i.e. <a spec=HTML>apply pending history changes</a>, <a spec=HTML>finalize a same-document navigation</a> and <a spec=HTML>finalize a cross-document navigation</a>?</p>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • apply pending history changes: only if we want to support prefetching reloads. Which I'm not sure we do?
  • finalize a same-document navigation: no, prefetching is not relevant there
  • finalize a cross-document navigation: yes, plumbing it through here is necessary for the path navigate -> finalize a cross-document navigation -> apply the history step.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

support prefetching reloads

There is a WPT already for reload (#212 (comment)), but maybe just to check the Chromium behavior?
https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/speculation-rules/prefetch/prefetch-traverse-reload.sub.html

navigate -> finalize a cross-document navigation -> apply the history step

Do you have examples/test cases where prefetched results would be used in this code path? (I'm not familiar with how "finalize a cross-document navigation" works)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a WPT already for reload (#212 (comment)), but maybe just to check the Chromium behavior?

Ah OK, I am happy to keep it then.

Do you have examples/test cases where prefetched results would be used in this code path? (I'm not familiar with how "finalize a cross-document navigation" works)

This is the most basic code path. E.g. this is the code path which clicking a link or doing location.href goes through.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://html.spec.whatwg.org/multipage/browsing-the-web.html#reload says:

It is intentional that the resulting call to apply the history step does not pass sourceSnapshotParams or initiatorToCheck.

So probably we shouldn't pass sourceDocumentForPrefetches as well?

Also, how about passing sourceDocumentForPrefetches (or its prefetch records) via sourceSnapshotParams?

Pros: It might be consistent with the existing decisions whether we should pass sourceDocument-related informatio n (sourceSnapshotParams or sourceDocumentForPrefetches) or not

Cons?: this means not passing sourceDocumentForPrefetches in finalize a cross-document navigation. IIUC sourceDocumentForPrefetches will be still passed for ordinal cross-document navigations via navigate -> attempt to populate the history entry's document -> creating navigation params by fetching, even if we don't pass sourceDocumentForPrefetches via navigate -> finalize a cross-document navigation though (I'm not sure the differences between the two paths, but probably the path via attempt to populate the history entry's document is the primary one?).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay; I got sick :(.

So probably we shouldn't pass sourceDocumentForPrefetches as well?

Hmm, I'm not sure. Mostly, sourceSnapshotParams and initiatorToCheck are used for security checks which (for some reason) browsers decide to not perform on reloads. The only thing that's kind of similar to how sourceDocumentForPrefetches is used is sourceSnapshotParams's fetch client, which is used to determine referrer and such. (E.g. for reloads, it always looks like the page is reloading itself, according to the Referer header.)

Cons?: this means not passing sourceDocumentForPrefetches in finalize a cross-document navigation. IIUC sourceDocumentForPrefetches will be still passed for ordinal cross-document navigations via navigate -> attempt to populate the history entry's document -> creating navigation params by fetching, even if we don't pass sourceDocumentForPrefetches via navigate -> finalize a cross-document navigation though (I'm not sure the differences between the two paths, but probably the path via attempt to populate the history entry's document is the primary one?).

Sorry, I realize I was misleading in what I said earlier. The paths are:

  • push/replace navigation: navigate -> attempt to populate -> finalize a cross-document navigation -> apply the history step. In apply the history step, targetEntry's document will be present, because of the earlier attempt to populate step.

  • reload navigation: reload -> apply pending history changes -> apply the history step -> attempt to populate. This time we reach attempt to populate from apply the history step, because targetEntry's document state's reload pending is true

  • back/forward navigation, bfcache: traverse the history by a delta -> apply the history step. In apply the history step, targetEntry's document will be present, because bfcache.

  • back/forward navigation, non-bfcache: traverse the history by a delta -> apply the history step -> attempt to populate. This time we reach attempt to populate from apply the history step, because targetEntry's document is null, because no bfcache.

Does that make sense? Feel free to grab me in person or in realtime if it doesn't; I know this stuff is complicated and I don't want to be confusing about it again.

So, I think your idea of putting sourceDocumentForPrefetches or the prefetch records in source snapshot params mostly works, and feels elegant. The consequence would be that reloads can only use prefetch records from their own document though, e.g. if you had this setup:

  • Parent loads a.html in an iframe
  • Later, parent prefetches a.html
  • Parent calls frames[0].reload()

then the prefetch would not be used. Maybe that's fine, because it's congruent with how the fetch client is set to frames[0] instead of to the parent?

Another elegant part of putting the prefetch records (not sourceDocumentForPrefetches) in source snapshot params is that if we start storing the prefetch records on a wider scope, per #266, it will not change very much: it will just change the snapshotting call to grab them from a different place.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, thank you for inputs and clarifications! Then I'll draft the spec to put prefetch records to source snapshot params.

I'm also less sure about reload's behavior here, but I feel we can prioritize (at least for now) the elegance/consistency of the spec architecture by putting the prefetch records to source snapshot params, and then later (after #266) we can revisit the reload behavior if actually needed in the wild.

If we make prefetch records scoped by network partition keys, I imagine prefetch records would be partitioned by the result of determine the network partition key given request’s client (because sourceDocumentForPrefetches basically corresponds to source snapshot params' client), while HTTP caches for navigation requests are partitioned by the result of determine the network partition key given request’s reserved client, which is perhaps simple.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use source snapshot params.

prefetch.bs Outdated Show resolved Hide resolved
@hiroshige-g hiroshige-g changed the title Use sourceDocument for prefetch lookup in prerendering navigation Use sourceDocument if set for prefetch lookup Apr 17, 2023
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 17, 2023
In these test cases (except for "<a>" subtest), sourceDocument
is different from navigable's active document, and thus
the behavior is affected by
WICG/nav-speculation#267.

Chromium's status:

- "<a>" subtest - already passing
- "location.href across iframe" subtest - failing, will pass after [1].
- Other tests - failing even after [1] (https://crbug.com/1432886).

[1] https://chromium-review.googlesource.com/c/chromium/src/+/4372403

Bug: 1432886, WICG/nav-speculation#267
Change-Id: I4098347c42f45188811700fcc8d7925bcc3c4162
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 17, 2023
In these test cases (except for "<a>" subtest), sourceDocument
is different from navigable's active document, and thus
the behavior is affected by
WICG/nav-speculation#267.

Chromium's status:

- "<a>" subtest - already passing
- "location.href across iframe" subtest - failing, will pass after [1].
- Other tests - failing even after [1] (https://crbug.com/1432886).

[1] https://chromium-review.googlesource.com/c/chromium/src/+/4372403

Bug: 1432886, WICG/nav-speculation#267
Change-Id: I4098347c42f45188811700fcc8d7925bcc3c4162
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 17, 2023
WPT updates for WICG/nav-speculation#267:

- Updated the expected behavior for an existing test:
  `prerender/prefetch.https.html`.
- Added other prefetch test cases.

Except for "<a>" subtest, `sourceDocument` is different from
`navigable's active document`.

Chromium's status:

- "<a>" subtest - already passing
- Others -- failing. Some of them will pass after [1],
  and remaining failures after [1] are tracked by
  https://crbug.com/1432886.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/4372403

Bug: 1432886, 1422815, WICG/nav-speculation#267
Change-Id: I4098347c42f45188811700fcc8d7925bcc3c4162
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 20, 2023
WPT updates for WICG/nav-speculation#267:

- Updated the expected behavior for an existing test:
  `prerender/prefetch.https.html`.
- Added other prefetch test cases.

Except for "<a>" subtest, `sourceDocument` is different from
`navigable's active document`.

Chromium's status:

- "<a>" subtest - already passing
- Others -- failing. Some of them will pass after [1],
  and remaining failures after [1] are tracked by
  https://crbug.com/1432886.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/4372403

Bug: 1432886, 1422815, WICG/nav-speculation#267
Change-Id: I4098347c42f45188811700fcc8d7925bcc3c4162
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 20, 2023
WPT updates for WICG/nav-speculation#267:

- Updated the expected behavior for an existing test:
  `prerender/prefetch.https.html`.
- Added other prefetch test cases.

Except for "<a>" subtest, `sourceDocument` is different from
`navigable's active document`.

Chromium's status:

- "<a>" subtest - already passing
- Others -- failing. Some of them will pass after [1],
  and remaining failures after [1] are tracked by
  https://crbug.com/1432886.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/4372403

Bug: 1432886, 1422815, WICG/nav-speculation#267
Change-Id: I4098347c42f45188811700fcc8d7925bcc3c4162
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 20, 2023
WPT updates for WICG/nav-speculation#267:

- Updated the expected behavior for an existing test:
  `prerender/prefetch.https.html`.
- Added other prefetch test cases.

Except for "<a>" subtest, `sourceDocument` is different from
`navigable's active document`.

Chromium's status:

- "<a>" subtest - already passing
- Others -- failing. Some of them will pass after [1],
  and remaining failures after [1] are tracked by
  https://crbug.com/1432886.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/4372403

Bug: 1432886, 1422815, WICG/nav-speculation#267
Change-Id: I4098347c42f45188811700fcc8d7925bcc3c4162
@hiroshige-g
Copy link
Author

@ArthurSonzogni FYI.
sourceSnapshotParams fallbacks to navigable's active document's snapshot at Step 12.6.4 of https://html.spec.whatwg.org/multipage/browsing-the-web.html#apply-the-history-step, which might be similar fallback you mentioned in the codereview comment https://chromium-review.googlesource.com/c/chromium/src/+/4372403/comment/bc534a9a_458b492c/.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 1, 2023
WPT updates for WICG/nav-speculation#267:

- Updated the expected behavior for an existing test:
  `prerender/prefetch.https.html`.
- Added other prefetch test cases.

Except for "<a>" subtest, `sourceDocument` is different from
`navigable's active document`.

Chromium's status:

- "<a>" subtest - already passing
- Others -- failing. Some of them will pass after [1],
  and remaining failures after [1] are tracked by
  https://crbug.com/1432886.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/4372403

Bug: 1432886, 1422815, WICG/nav-speculation#267
Change-Id: I4098347c42f45188811700fcc8d7925bcc3c4162
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 1, 2023
WPT updates for WICG/nav-speculation#267:

- Updated the expected behavior for an existing test:
  `prerender/prefetch.https.html`.
- Added other prefetch test cases.

Except for "<a>" subtest, `sourceDocument` is different from
`navigable's active document`.

Chromium's status:

- "<a>" subtest - already passing
- Others -- failing. Some of them will pass after [1],
  and remaining failures after [1] are tracked by
  https://crbug.com/1432886.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/4372403

Bug: 1432886, 1422815, WICG/nav-speculation#267
Change-Id: I4098347c42f45188811700fcc8d7925bcc3c4162
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 1, 2023
WPT updates for WICG/nav-speculation#267:

- Updated the expected behavior for an existing test:
  `prerender/prefetch.https.html`.
- Added other prefetch test cases.

Except for "<a>" subtest, `sourceDocument` is different from
`navigable's active document`.

Chromium's status:

- "<a>" subtest - already passing
- Others -- failing. Some of them will pass after [1],
  and remaining failures after [1] are tracked by
  https://crbug.com/1432886.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/4372403

Bug: 1440607, 1432886, 1422815, WICG/nav-speculation#267
Change-Id: I4098347c42f45188811700fcc8d7925bcc3c4162
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 8, 2023
WPT updates for WICG/nav-speculation#267:

- Updated the expected behavior for an existing test:
  `prerender/prefetch.https.html`.
- Added other prefetch test cases.

Except for "<a>" subtest, `sourceDocument` is different from
`navigable's active document`.

Chromium's status:

- "<a>" subtest - already passing
- Others -- failing. Some of them will pass after [1],
  and remaining failures after [1] are tracked by
  https://crbug.com/1432886.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/4372403

Bug: 1440607, 1432886, 1422815, WICG/nav-speculation#267
Change-Id: I4098347c42f45188811700fcc8d7925bcc3c4162
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4422475
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1141005}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 8, 2023
WPT updates for WICG/nav-speculation#267:

- Updated the expected behavior for an existing test:
  `prerender/prefetch.https.html`.
- Added other prefetch test cases.

Except for "<a>" subtest, `sourceDocument` is different from
`navigable's active document`.

Chromium's status:

- "<a>" subtest - already passing
- Others -- failing. Some of them will pass after [1],
  and remaining failures after [1] are tracked by
  https://crbug.com/1432886.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/4372403

Bug: 1440607, 1432886, 1422815, WICG/nav-speculation#267
Change-Id: I4098347c42f45188811700fcc8d7925bcc3c4162
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4422475
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1141005}
: <dfn for="source snapshot params">prefetch records</dfn>
:: a a [=list=] of [=prefetch records=].

When to [=snapshot source snapshot params=], set [=source snapshot params/prefetch records=] to <var ignore>sourceDocument</var>'s [=Document/prefetch records=].
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably make a [=list/clone=] here (https://infra.spec.whatwg.org/#list-clone) to reflect the idea we're snapshotting.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure: in general creating a snapshot would be a good idea to avoid unintentional race conditions, while in this case not taking a clone might be also an option,

  • As [=list/clone=] is a shallow copy, this isn't a complete frozen snapshot of the prefetch records.
  • When a prefetch is still ongoing at the time of navigation start and we want to use the prefetch result after response is received after navigation start, we might need intentional interactions via (non-snapshot) prefetch records (IIUC such case is not yet specified so though)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I can see your concerns. However, I think it'd most fit the spirit of source snapshot params to start with a shallow clone for now, reflecting the idea that any prefetches added after the prerender navigation starts, should not influence the prerender navigation. Similar to how, e.g., changes to the page's origin or sandboxing flags after navigation starts, should not affect the (normal, non-prerender) navigation.

I agree that it's a little strange that we're not doing a deep clone. But that's kind of the nature of prefetch records being things that are updated over time. I think that part is OK.

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request May 22, 2023
…cord lookup, a=testonly

Automatic update from web-platform-tests
[WPT] Use sourceDocument for prefetch record lookup

WPT updates for WICG/nav-speculation#267:

- Updated the expected behavior for an existing test:
  `prerender/prefetch.https.html`.
- Added other prefetch test cases.

Except for "<a>" subtest, `sourceDocument` is different from
`navigable's active document`.

Chromium's status:

- "<a>" subtest - already passing
- Others -- failing. Some of them will pass after [1],
  and remaining failures after [1] are tracked by
  https://crbug.com/1432886.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/4372403

Bug: 1440607, 1432886, 1422815, WICG/nav-speculation#267
Change-Id: I4098347c42f45188811700fcc8d7925bcc3c4162
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4422475
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1141005}

--

wpt-commits: c2094381f1c8ee7af3b9971d705d5fea7245e49c
wpt-pr: 39518
ErichDonGubler pushed a commit to erichdongubler-mozilla/firefox that referenced this pull request May 23, 2023
…cord lookup, a=testonly

Automatic update from web-platform-tests
[WPT] Use sourceDocument for prefetch record lookup

WPT updates for WICG/nav-speculation#267:

- Updated the expected behavior for an existing test:
  `prerender/prefetch.https.html`.
- Added other prefetch test cases.

Except for "<a>" subtest, `sourceDocument` is different from
`navigable's active document`.

Chromium's status:

- "<a>" subtest - already passing
- Others -- failing. Some of them will pass after [1],
  and remaining failures after [1] are tracked by
  https://crbug.com/1432886.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/4372403

Bug: 1440607, 1432886, 1422815, WICG/nav-speculation#267
Change-Id: I4098347c42f45188811700fcc8d7925bcc3c4162
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4422475
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1141005}

--

wpt-commits: c2094381f1c8ee7af3b9971d705d5fea7245e49c
wpt-pr: 39518
aarongable pushed a commit to chromium/chromium that referenced this pull request May 23, 2023
This CL uses initiator's Document/RenderFrameHost
(which basically corresponds to `sourceDocument` in the spec)
when available for prefetch lookup.

This is to align with the Spec PR:
WICG/nav-speculation#267

This CL makes prefetched results used for prerendering,
if they are initiated by the same Document.
In ordinal prerendering cases, the initiator is the same as
`PrerendererImpl::render_frame_host_`.

Some other cases affected by the spec PR aren't fixed by
this CL (e.g. https://crbug.com/1432886), because they are
also blocked by other issues (removal of
`PrefetchDocumentManager::DidStartNavigation()`, etc).

Bug: 1440607, 1422815, 1432886, 1431804, WICG/nav-speculation#261
Change-Id: I8f15220c30c9199b0616704db7228ff1c604ed74
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4372403
Reviewed-by: Max Curran <curranmax@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Reviewed-by: Kouhei Ueno <kouhei@chromium.org>
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Reviewed-by: Lingqi Chi <lingqi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1148246}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants