Skip to content

Truly independent web browser

LibWeb: Prepare to run script before notifying the committed entry

Andreas Klingdc3c0db42776
diff --git a/Libraries/LibWeb/HTML/Navigation.cpp b/Libraries/LibWeb/HTML/Navigation.cpp
index ca5a0dfc8da..a983e6bafb6 100644
--- a/Libraries/LibWeb/HTML/Navigation.cpp
+++ b/Libraries/LibWeb/HTML/Navigation.cpp
@@ -1648,6 +1648,12 @@ void Navigation::update_the_navigation_api_entries_for_a_same_document_navigatio
}
}
+ // NB: Resolving the committed promise in step 8 needs a running execution context, and cleaning that up would
+ // perform a microtask checkpoint when nothing else is running script, such as during a traversal. So this
+ // prepares to run script ahead of step 11, which keeps promise reactions from running before the
+ // currententrychange event handlers and the intercept() handlers.
+ TemporaryExecutionContext execution_context { realm, TemporaryExecutionContext::CallbacksEnabled::Yes };
+
// 8. If navigation's ongoing API method tracker is non-null, then notify about the committed-to entry
// given navigation's ongoing API method tracker and the current entry of navigation.
// NOTE: It is important to do this before firing the dispose or currententrychange events,
@@ -1663,7 +1669,7 @@ void Navigation::update_the_navigation_api_entries_for_a_same_document_navigatio
auto api_method_tracker = m_ongoing_api_method_tracker;
// 11. Prepare to run script given navigation's relevant settings object.
- TemporaryExecutionContext execution_context { realm, TemporaryExecutionContext::CallbacksEnabled::Yes };
+ // NB: Done before step 8.
// 12. Fire an event named currententrychange at navigation using NavigationCurrentEntryChangeEvent,
// with its navigationType attribute initialized to navigationType and its from initialized to oldCurrentNHE.
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-change-history-scroll-restoration-during-promise.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-change-history-scroll-restoration-during-promise.txt
index 0f16b28db0e..5a61e017700 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-change-history-scroll-restoration-during-promise.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/after-transition-change-history-scroll-restoration-during-promise.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail scroll: after-transition should ignore history.scrollRestoration even if it changes in the middle of the navigation
\ No newline at end of file
+1 Pass
+Pass scroll: after-transition should ignore history.scrollRestoration even if it changes in the middle of the navigation
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-after-dispatch.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-after-dispatch.txt
index b037c22e2b5..44cedfbffdd 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-after-dispatch.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-after-dispatch.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail scroll: scroll() should work after a navigate event dispatch
\ No newline at end of file
+1 Pass
+Pass scroll: scroll() should work after a navigate event dispatch
\ No newline at end of file