LibWeb/HTML: Scroll to the fragment before loading the document

Otherwise nowhere ends up scrolling to the fragment specified by the
fragment in document's URL. This fixes ladybird scrolling to the
correct location in the document when navigating to a link that
has a fragment, e.g:

https://html.spec.whatwg.org/multipage/browsing-the-web.html#try-to-scroll-to-the-fragment

As well as use of the :target selector.
This commit is contained in:
Shannon Booth 2025-01-15 17:15:25 +13:00 committed by Sam Atkins
parent e74ca82083
commit 51102254b5
Notes: github-actions[bot] 2025-01-15 12:44:49 +00:00
4 changed files with 49 additions and 6 deletions

View file

@ -310,6 +310,9 @@ void HTMLParser::the_end(GC::Ref<DOM::Document> document, GC::Ptr<HTMLParser> pa
(void)document->scripts_to_execute_when_parsing_has_finished().take_first();
}
// FIXME: Spec bug: https://github.com/whatwg/html/issues/10914
document->scroll_to_the_fragment();
// 6. Queue a global task on the DOM manipulation task source given the Document's relevant global object to run the following substeps:
queue_global_task(HTML::Task::Source::DOMManipulation, *document, GC::create_function(heap, [document] {
// 1. Set the Document's load timing info's DOM content loaded event start time to the current high resolution time given the Document's relevant global object.