Skip to content

Truly independent web browser

LibWeb: Clear the target element when the fragment does not exist

Andreas Kling9354edbdb5b5
diff --git a/Libraries/LibWeb/HTML/NavigateEvent.cpp b/Libraries/LibWeb/HTML/NavigateEvent.cpp
index 9012801215f..5e806e4b0ee 100644
--- a/Libraries/LibWeb/HTML/NavigateEvent.cpp
+++ b/Libraries/LibWeb/HTML/NavigateEvent.cpp
@@ -263,6 +263,9 @@ void NavigateEvent::process_scroll_behavior()
// 2. If document's indicated part is null, then scroll to the beginning of the document given document. [CSSOMVIEW]
auto indicated_part = document.determine_the_indicated_part();
if (indicated_part.has<DOM::Element*>() && indicated_part.get<DOM::Element*>() == nullptr) {
+ // INTEROP: Other browsers also clear the document's target element here, as scrolling to the fragment
+ // does when the indicated part is null.
+ document.set_target_element(nullptr);
document.scroll_to_the_beginning_of_the_document();
}
diff --git a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-clears-target-when-fragment-does-not-exist.txt b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-clears-target-when-fragment-does-not-exist.txt
index fdc76cdc083..4cf2210a559 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-clears-target-when-fragment-does-not-exist.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/navigation-api/scroll-behavior/manual-scroll-clears-target-when-fragment-does-not-exist.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail scroll: scroll() should clear the CSS :target element when the fragment does not exist
\ No newline at end of file
+1 Pass
+Pass scroll: scroll() should clear the CSS :target element when the fragment does not exist
\ No newline at end of file