mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-08 10:36:02 +00:00
LibWeb: Respect scroll position set by script during page load
When setting scroll position during page load we need to consider
whether we actually have a fragment to scroll to. A script may already
have run at that point and may already have set a scroll position.
If there is an actual fragment to scroll to, it is fine to scroll to
that fragment, since it should take precedence. If we don't have a
fragment however, we should not unnecessarily overwrite the scroll
position set by the script back to (0, 0).
Since this problem is caused by a spec bug, I have tested the behavior
in the three major browsers engines. Unfortunately they do not agree
fully with each other. If there is no fragment at all (e.g. `foo.html`),
all browsers will respect the scroll position set by the script. If
there is a fragment (e.g. `foo.html#bar`), all browsers will set the
scroll position to the fragment element and ignore the one set by
script. However, when the fragment is empty (e.g. `foo.html#`), then
Blink and WebKit will set scroll position to the fragment, while Gecko
will set scroll position from script. Since all of this is ad-hoc
behavior anyway, I simply implemented the Blink/WebKit behavior because
of the majority vote for now.
This fixes a regression introduced in 51102254b5
.
This commit is contained in:
parent
53bf0ef225
commit
0e1eb4d4a7
Notes:
github-actions[bot]
2025-03-10 16:15:16 +00:00
Author: https://github.com/InvalidUsernameException
Commit: 0e1eb4d4a7
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3854
3 changed files with 22 additions and 2 deletions
12
Tests/LibWeb/Text/input/scroll-during-page-load.html
Normal file
12
Tests/LibWeb/Text/input/scroll-during-page-load.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="include.js"></script>
|
||||
<style>
|
||||
div { height: 200vh; }
|
||||
</style>
|
||||
<div></div>
|
||||
<script>
|
||||
window.scrollTo(0, 200);
|
||||
test(() => {
|
||||
println(`Scroll position: ${window.scrollY}px`);
|
||||
});
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue