Repository navigation
fix: make webContents.centerSelection() work on Windows and Linux - #55909
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KX1hkNiiBq2fQEsXWusxpm
There was a problem hiding this comment.
I reviewed this PR and found no bugs. It adds a Chromium patch under patches/, which has code owners, so someone who can see the upstream tree should still look at it.
What was reviewed (standalone clone, so no Chromium sources were available):
- The patch only removes the
#if BUILDFLAG(IS_MAC)/#endifpair inWebContentsImpl::CenterSelection(). It is listed inpatches/chromium/.patches, and its message explains how to tell when it can be dropped.docs/api/web-contents.mdandwebview-tag.mdhave no macOS-only tag oncenterSelection(), so no doc change is needed. - The new spec is in a
serialsuite, uses vitest matchers and puts noexpect()inside listeners. One question: the test's comment says document scrolls are animated, butwaitUntilstops as soon asscrollY !== 0(spec/api-web-contents.spec.ts:3016) and then asserts the final centered position. If the scroll really is animated, this could flake. Waiting on the centered condition itself would avoid that. - I couldn't check from here whether the patch applies or whether the scroll is animated. I didn't run the spec either.
Extended reasoning...
The change adds one Chromium patch that removes a Mac-only build guard around WebContentsImpl::CenterSelection(), registers it in patches/chromium/.patches and adds one serial spec. It touches no security-sensitive surface: no IPC, permissions or webPreferences changes. I deferred because /patches/ is owned by patch owners in .github/CODEOWNERS, and because this standalone clone has no upstream Chromium code to check the hunk or the scroll behavior against.
Wait until the middle of the selection is within tolerance of the middle of the viewport instead of until the page has scrolled at all, and say why we wait: centerSelection() reaches the renderer asynchronously, but the scroll itself (RevealSelection -> ScrollRectToVisible) is instant since the page does not use CSS smooth scrolling. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KX1hkNiiBq2fQEsXWusxpm
|
Release Notes Persisted
|
|
I was unable to backport this PR to "44-x-y" cleanly; |
|
I have automatically backported this PR to "45-x-y", please check out #55915 |
|
I have automatically backported this PR to "46-x-y", please check out #55916 |
|
claude[bot] has manually backported this PR to "44-x-y", please check out #55950 |
…5950) fix: make webContents.centerSelection() work on Windows and Linux (#55909) * fix: make webContents.centerSelection() work on Windows and Linux Claude-Session: https://claude.ai/code/session_01KX1hkNiiBq2fQEsXWusxpm * test: wait for the centred position in the centerSelection spec Wait until the middle of the selection is within tolerance of the middle of the viewport instead of until the page has scrolled at all, and say why we wait: centerSelection() reaches the renderer asynchronously, but the scroll itself (RevealSelection -> ScrollRectToVisible) is instant since the page does not use CSS smooth scrolling. Claude-Session: https://claude.ai/code/session_01KX1hkNiiBq2fQEsXWusxpm --------- (cherry picked from commit ef8d809) Claude-Session: https://claude.ai/code/session_01KX1hkPAirbYV7a7v3Ck4FB Co-authored-by: Claude <[email protected]>
Requested by David Babenko-Sanders · Slack thread
Description of Change
webContents.centerSelection()and<webview>.centerSelection()do nothing on Windows and Linux, because Chromium'sWebContentsImpl::CenterSelection()wraps its whole body in#if BUILDFLAG(IS_MAC). That guard was copied from the neighbouringCopyToFindPboard()whenCenterSelectionwas added in https://crrev.com/c/4258445;CopyToFindPboard()needs it because only macOS has a find pasteboard, but the rest of theCenterSelectionpath (theFrameWidgetInputHandlermojom message,FrameWidgetInputHandlerImpl,WebFrameWidgetImplandWebLocalFrameImpl::CenterSelection()) is platform-neutral. A new Chromium patch,fix_allow_webcontentsimpl_centerselection_on_all_platforms.patch, removes the guard, and should be upstreamed. A new serialcenterSelection()spec inapi-web-contents.spec.tsselects text far below the fold in a shown, focused window and checks thatcenterSelection()scrolls it to the middle of the viewport on every platform. Electron wasn't built locally: the new test was confirmed to fail on an unpatched 47.0.0-nightly.20261117 on Linux, so CI is the first run with the patch applied.Checklist
Release Notes
🤖 Generated with Claude Code
https://claude.ai/code/session_01KX1hkNiiBq2fQEsXWusxpm
Notes: Fixed
webContents.centerSelection()so that it works on Windows and Linux.