Skip to content

AutoFill unexpectedly scrolls to reveal text fields when inserting text#45476

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
whsieh:eng/293098
May 16, 2025
Merged

AutoFill unexpectedly scrolls to reveal text fields when inserting text#45476
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
whsieh:eng/293098

Conversation

@whsieh
Copy link
Copy Markdown
Member

@whsieh whsieh commented May 16, 2025

76c1453

AutoFill unexpectedly scrolls to reveal text fields when inserting text
https://bugs.webkit.org/show_bug.cgi?id=293098
rdar://149708409

Reviewed by Aditya Keerthi and Abrar Rahman Protyasha.

When performing AutoFill, Safari's injected script creates and dispatches `TextEvent`s in each text
field to simulate text input, in such a way that the resulting DOM events dispatched to the page
closely match those dispatched when typing manually.

While generally good for AutoFill compatibility, this results in some unwanted behaviors, such as
the scroll position potentially flickering if some of the form fields lie offscreen, due to the fact
that we'll attempt to reveal the selection when dispatching `TextEvent`.

We already avoid scrolling to reveal the selection when using `document.execCommand(…)` to insert
text, so we can fix this bug by applying a similar treatment to the case where `TextEvent` DOM
events are untrusted (created using `Document.createEvent` / `Event.initTextEvent`).

* LayoutTests/editing/inserting/no-scroll-after-text-event-created-from-bindings-expected.txt: Added.
* LayoutTests/editing/inserting/no-scroll-after-text-event-created-from-bindings.html: Added.

Add a test that inserts text by creating and dispatching a `TextEvent` in a focused field.

* Source/WebCore/editing/Editor.cpp:
(WebCore::Editor::insertTextWithoutSendingTextEvent):

Canonical link: https://commits.webkit.org/295008@main

ce43d75

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ⏳ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-cairo
🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ❌ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 ✅ 🛠 playstation
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@whsieh whsieh requested a review from rniwa as a code owner May 16, 2025 03:37
@whsieh whsieh self-assigned this May 16, 2025
@whsieh whsieh added the New Bugs Unclassified bugs are placed in this component until the correct component can be determined. label May 16, 2025
Comment thread Source/WebCore/editing/Editor.cpp Outdated
@whsieh whsieh added the merge-queue Applied to send a pull request to merge-queue label May 16, 2025
https://bugs.webkit.org/show_bug.cgi?id=293098
rdar://149708409

Reviewed by Aditya Keerthi and Abrar Rahman Protyasha.

When performing AutoFill, Safari's injected script creates and dispatches `TextEvent`s in each text
field to simulate text input, in such a way that the resulting DOM events dispatched to the page
closely match those dispatched when typing manually.

While generally good for AutoFill compatibility, this results in some unwanted behaviors, such as
the scroll position potentially flickering if some of the form fields lie offscreen, due to the fact
that we'll attempt to reveal the selection when dispatching `TextEvent`.

We already avoid scrolling to reveal the selection when using `document.execCommand(…)` to insert
text, so we can fix this bug by applying a similar treatment to the case where `TextEvent` DOM
events are untrusted (created using `Document.createEvent` / `Event.initTextEvent`).

* LayoutTests/editing/inserting/no-scroll-after-text-event-created-from-bindings-expected.txt: Added.
* LayoutTests/editing/inserting/no-scroll-after-text-event-created-from-bindings.html: Added.

Add a test that inserts text by creating and dispatching a `TextEvent` in a focused field.

* Source/WebCore/editing/Editor.cpp:
(WebCore::Editor::insertTextWithoutSendingTextEvent):

Canonical link: https://commits.webkit.org/295008@main
@webkit-commit-queue
Copy link
Copy Markdown
Collaborator

Committed 295008@main (76c1453): https://commits.webkit.org/295008@main

Reviewed commits have been landed. Closing PR #45476 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 76c1453 into WebKit:main May 16, 2025
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label May 16, 2025
@whsieh whsieh deleted the eng/293098 branch May 16, 2025 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

New Bugs Unclassified bugs are placed in this component until the correct component can be determined.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants