Skip to content

Commit

Permalink
Bug 1863646 [wpt PR 43008] - Fire the navigate event earlier for cros…
Browse files Browse the repository at this point in the history
…s-document traversals, a=testonly

Automatic update from web-platform-tests
Fire the navigate event earlier for cross-document traversals

This earlier timing ensures that we fire the navigate event in the old
document when a traversal is served from the bfcache, and is more consistent with non-history cross-document navigate events.

Currently, cross-document traversals fire the navigate event at the
last possible time: during commit in the renderer, the navigate event
is fired in the old document immediately before it is unloaded. The
navigate event is not allowed to cancel or intercept a cross-document
traversal, otherwise this timing would be too late. We did not
reach a firm conclusion on when to fire the navigate event for
cross-document traversals during the design of the Navigation API
(see WICG/navigation-api#207), and this
was the latest of the options considered.

This timing has two problems:
1. Traversals served by the back forward cache don't "commit". So
   the navigate event is erroneously omitted.
2. The navigate event fires after redirects, where for other
   cross-document navigations, it fires before redirects.

This CL adds plumbing for the browser to trigger the navigate event
to fire in the renderer in the cross-document traversal case, and
moves the time of the navigate event earlier. It now fires after
the browser process has decided to allow the traversal to start
(i.e., after beforeunload has been fired in any relevant frames, and
after start throttles). In the cross-document traversal case where
the navigation is not served from bfcache, this will fire the
navigate event in parallel with the network request (which is ok
because the navigate event can't intercept or cancel the navigation,
this timing would not be permissible for other navigation types where
the navigate event has more power over the navigation). In the case
where no network request is needed (bfcache, about:blank, etc.), the
navigate event task gets sent to the renderer immediately before the
commit/activation task.

Bug: 1475907
Change-Id: I1ef7337e2d85f9cdbfc0110f9f4fe3bcd4dea75d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5011394
Reviewed-by: Domenic Denicola <domenicchromium.org>
Commit-Queue: Nate Chapin <japhetchromium.org>
Reviewed-by: Charlie Reis <creischromium.org>
Reviewed-by: Will Harris <wfhchromium.org>
Cr-Commit-Position: refs/heads/main{#1229455}

--

wpt-commits: b92c3a8c78b102518261a78e17a27b5e6f2efb8a
wpt-pr: 43008

UltraBlame original commit: 86b3ba75ab49e48c031d5abaebdf2aa406ca5cc8
  • Loading branch information
marco-c committed Dec 7, 2023
1 parent 153fed5 commit 9116bc3
Show file tree
Hide file tree
Showing 4 changed files with 755 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
<
!
doctype
html
>
<
script
src
=
"
/
resources
/
testharness
.
js
"
>
<
/
script
>
<
script
src
=
"
/
resources
/
testharnessreport
.
js
"
>
<
/
script
>
<
script
src
=
"
/
common
/
utils
.
js
"
>
<
/
script
>
<
script
src
=
"
/
common
/
dispatcher
/
dispatcher
.
js
"
>
<
/
script
>
<
script
src
=
"
/
html
/
browsers
/
browsing
-
the
-
web
/
back
-
forward
-
cache
/
resources
/
helper
.
sub
.
js
"
>
<
/
script
>
<
script
>
runBfcacheTest
(
{
targetOrigin
:
originSameOrigin
funcBeforeBackNavigation
:
(
)
=
>
{
window
.
did_navigate
=
false
;
navigation
.
onnavigate
=
(
)
=
>
window
.
did_navigate
=
true
;
}
async
funcAfterAssertion
(
pageA
pageB
)
{
/
/
When
funcAfterAssertion
is
called
we
'
ve
already
navigated
to
pageB
/
/
then
gone
back
to
pageA
with
bfcache
.
Now
go
forward
to
pageB
so
we
can
/
/
observe
whether
the
navigate
event
fired
.
await
pageA
.
execute_script
(
(
)
=
>
history
.
forward
(
)
)
;
await
pageB
.
execute_script
(
waitForPageShow
)
;
assert_true
(
await
pageB
.
execute_script
(
(
)
=
>
window
.
did_navigate
)
)
;
}
}
"
navigate
event
should
fire
when
traversing
to
a
bfcache
hit
"
)
;
<
/
script
>
Original file line number Diff line number Diff line change
Expand Up @@ -301,86 +301,39 @@
.
index
;
/
/
One
might
be
surprised
that
navigate
does
not
fire
.
(
It
does
fire
for
the
/
/
corresponding
tests
of
navigation
.
navigate
(
)
let
onnavigate_called
=
false
;
i
.
e
.
this
is
/
/
traversal
-
specific
behavior
.
)
See
https
:
/
/
github
contentWindow
.
com
/
WICG
/
navigation
-
api
/
issues
/
207
/
/
for
some
discussion
.
onnavigate
=
(
)
=
>
onnavigate_called
=
true
;
i
.
contentWindow
.
navigation
.
onnavigate
onunload
=
t
.
unreached_func
(
"
onnavigate
onunload
should
not
be
Expand Down Expand Up @@ -494,6 +447,11 @@
null
)
;
assert_true
(
onnavigate_called
)
;
}
back
(
Expand Down
Loading

0 comments on commit 9116bc3

Please sign in to comment.