Skip to content

fix: keep the window content view from blocking accessibility hit-tests - #55334

Open
avrilmai wants to merge 9 commits into
electron:mainfrom
avrilmai:fix/content-view-a11y-hit-test
Open

avrilmai wants to merge 9 commits into
electron:mainfrom
avrilmai:fix/content-view-a11y-hit-test

Conversation

@avrilmai

@avrilmai avrilmai commented Oct 26, 2026 •

Copy link
Copy Markdown

Description of Change

This continues #53460, whose author is unable to follow up on it. The original
branch no longer applies to main, and the Windows verification the PR was
waiting for was never done. This PR carries the same fix, rebased on current
main, reuses the ContentViewTargeterDelegate that main already ships for
macOS, and adds the Windows/UIA verification.

Root cause. BrowserWindow adds its WebContentsView as a sibling of
the window's content view, inserted before it in the paint order, so that
views added to the content view are painted on top of the web content
(#41256). In shell/browser/api/electron_api_browser_window.cc:

The WebContentsView is added a sibling of BaseWindow's contentView (before
it in the paint order) so that any views added to BrowserWindow's
contentView will be painted on top of the BrowserWindow's WebContentsView.

The content view covers the whole window, so the default bounds check
(ViewTargeterDelegate::DoesIntersectRect, a check of the view's bounds) made
it win every hit-test: ViewAXPlatformNodeDelegate::HitTestSync tested the
children of the window's main view from the top down, and the content view,
being the topmost child, matched every point. It returned the empty container
instead of the web content. On Windows this intercepts
AccessibleObjectFromPoint, which is the legacy path NVDA uses for mouse
tracking, so the screen reader has nothing to report on the content (#42945).

The fix, in two parts.

  1. NativeWindowViews::SetContentView installs the same
    ContentViewTargeterDelegate that NativeWindowMac::SetContentView and
    NativeWindowMacRemote::SetContentView already install. The content view
    then only intersects a point where one of its children covers it, so
    accessibility hit-tests and view mouse targeting fall through to the
    WebContentsView underneath. Unlike the original PR, this reuses the shared
    delegate that already exists in main instead of moving it to
    native_window.cc.
  2. The content view is kept out of the accessibility tree while it has no
    visible child, and reappears as soon as it gets one. The rule is set in
    BaseWindow::SetContentView, so it covers the container created by
    BaseWindow as well as a view installed later through setContentView. A
    view whose only child is invisible counts as empty, the way the hit-test
    transparency ignores invisible children.

AI assistance. This change was prepared with AI assistance (MiniMax M3.1,
through a local assistant), and the commits carry Assisted-By: trailers as
described in the project's AI tool policy. The author is responsible for the
change and reviews the diff before the pull request is merged.

Windows verification

Measured with the procedure in docs/development/a11y-hit-test-verification/,
on Windows 11, 1920x1200, scale factor 1. The application under test opens a
900x700 window with five text blocks at fixed positions and leaves the content
view empty, as an ordinary BrowserWindow does.

Both Windows paths are queried at each point: AutomationElement.FromPoint
(UIA) and AccessibleObjectFromPoint (MSAA, the legacy path NVDA uses for
Electron applications, and what Inspect.exe shows in MSAA mode).

Before the fix, with the published Electron 45.0.0:

  • UIA: every point resolves to the web document.
  • MSAA: every point resolves to role=16 (ROLE_SYSTEM_PANE), with no name
    and no accessible child. That is the empty content view: a screen reader on
    the legacy path has nothing to announce.
  • The accessibility tree holds an extra empty container next to the web
    document.

After the fix, with the same change set built locally on Windows 11:

  • UIA: every point still resolves to the web document, unchanged.
  • MSAA: every point resolves to role=16 with one accessible child, the web
    document. The pointer now reaches the content of the page.
  • The empty container is gone from the accessibility tree.

The branch was rebased onto the current main after that local build; the
two commits it picked up do not touch the accessibility code.

With a view added to the content view (--avec-enfant), the content view is
no longer empty: it stays in the accessibility tree and keeps the hit-test
where one of its children covers the pointer. The objects the MSAA path
returns are the same before and after the fix in that configuration, because
the content view and the node carrying the web content have the same bounds
and the same number of accessible children: the first case is the
discriminating one.

Points raised in review

  • ContentViewTargeterDelegate was only listed in lib_sources_mac, so the
    new code would not have linked on Windows and Linux. It is now also listed in
    lib_sources_views.
  • The "hide the empty container" rule now covers every content view, not only
    the one created by BaseWindow.
  • An invisible child no longer keeps an empty container in the tree.

Related issues

Checklist

  • I have built and tested this change
  • I have filled out the PR description
  • I have reviewed and verified the changes — this box is the human author's
    to tick after reviewing the diff, as required by the project's AI tool
    policy
  • npm test passes locally — native accessibility hit-testing is not
    observable from the JS specs, so the verification above is done with the
    Windows UI Automation and MSAA APIs instead
  • relevant API documentation, tutorials, and examples are updated — the
    verification procedure is documented in
    docs/development/a11y-hit-test-verification/
  • PR release notes
    describe the change in a way relevant to app developers, and are
    capitalized, punctuated, and past tense

Release Notes

Notes: Fixed screen readers detecting an empty pane instead of the web contents of a BrowserWindow on Windows and Linux.

@welcome

welcome Bot commented Oct 26, 2026

Copy link
Copy Markdown

💖 Thanks for opening this pull request! 💖

Semantic PR titles

We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix.

Examples of commit messages with semantic prefixes:

  • fix: don't overwrite prevent_default if default wasn't prevented
  • feat: add app.isPackaged() method
  • docs: app.isDefaultProtocolClient is now available on Linux

Commit signing

This repo enforces commit signatures for all incoming PRs.
To sign your commits, see GitHub's documentation on Telling Git about your signing key.

PR tips

Things that will help get your PR across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ This PR contains unsigned commits. This repository enforces commit signatures
for all incoming PRs. To get your PR merged, please sign those commits
(git rebase --exec 'git commit -S --amend --no-edit -n' @{upstream}) and force push them to this branch
(git push --force-with-lease)

For more information on signing commits, see GitHub's documentation on Telling Git about your signing key.

BrowserWindow places its WebContentsView as a sibling of the window content view, below it in the paint order, so that views added to the content view are painted on top of the web content.

The content view covers the whole window, so the default bounds check made it win every hit-test: ViewAXPlatformNodeDelegate::HitTestSync returned the empty container instead of the web content, which broke NVDA mouse tracking (electron#42945).

Install the same ContentViewTargeterDelegate that macOS already uses, so the content view only intersects a point where one of its children covers it. Accessibility hit-tests and view mouse targeting then fall through to the WebContentsView.

Assisted-By: MiniMax M3.1 (MiniMax), Assistant IA local
The content view that BaseWindow creates is an empty container covering the whole window. Assistive technology reports it as an empty pane instead of the window content, and it shows up as an extra node when navigating the accessibility tree.

Keep that container out of the tree while it has no child view, and make it visible again as soon as it gets one. Only the container created by BaseWindow is treated this way, so a view set by the application through setContentView keeps its accessibility node.

Assisted-By: MiniMax M3.1 (MiniMax), Assistant IA local
Native accessibility hit-testing is not observable from the JS specs. These files reproduce the window described in electron#42945 and query the Windows UI Automation API, the same layer that NVDA uses for mouse tracking and that Inspect.exe displays.

Assisted-By: MiniMax M3.1 (MiniMax), Assistant IA local
The delegate was only listed in lib_sources_mac, so the code that installs it on Windows and Linux would not have linked. Add it to lib_sources_views, which is the list of the view sources built when the target is not macOS.

Assisted-By: MiniMax M3.1 (MiniMax), Assistant IA local
The rule was only set on the container that BaseWindow creates, so a view installed later through setContentView stayed an empty pane in the accessibility tree. Set it in BaseWindow::SetContentView instead, which covers both.

A container whose only child is invisible is empty on screen, so count the visible children rather than the raw child count, the way the hit-test transparency of the content view ignores invisible children.

Assisted-By: MiniMax M3.1 (MiniMax), Assistant IA local
Apply the display scale factor so that the measured points stay correct on a scaled display, write the measurements in the temporary directory instead of the source tree, and drop the unused conditions of the tree walk.

Assisted-By: MiniMax M3.1 (MiniMax), Assistant IA local
Explain which Windows path is broken and which one is not, how to run the measurement, and what the result looks like before and after the fix. Index the document in the development guides.

Assisted-By: MiniMax M3.1 (MiniMax), Assistant IA local
The verification procedure could not show the difference between the fixed
and the unfixed build: with a child view in the content view, the MSAA
hit-test returned the same number of accessible children before and after
the fix, because the empty container and the node carrying the web content
have the same bounds.

The test application now leaves the content view empty by default, as an
ordinary BrowserWindow does, and the child view becomes the --avec-enfant
option. The procedure documents what each configuration shows, and the
readme states the measured results instead of the expected ones.

Assisted-By: MiniMax M3.1 (MiniMax), Assistant IA local
@avrilmai
avrilmai force-pushed the fix/content-view-a11y-hit-test branch from 6dab3b0 to 9b808f2 Compare October 26, 2026 03:14
With a child view in the content view, the MSAA objects returned before and
after the fix are the same: the content view and the node that carries the
web content have the same bounds and the same number of accessible children.
The procedure now says so, instead of claiming a difference that the
measurement cannot show.

Assisted-By: MiniMax M3.1 (MiniMax), Assistant IA local
@avrilmai
avrilmai force-pushed the fix/content-view-a11y-hit-test branch from f7feeef to 93eb8a1 Compare October 26, 2026 09:03
@github-actions github-actions Bot removed the needs-signed-commits Currently some or all of the commits in this PR are not signed label Oct 26, 2026
@mlaurencin

Copy link
Copy Markdown
Member

@avrilmai docs/development is not the proper location for your testing. Please refer to the testing guidance here to properly design and place your tests. Also please be consistent with your use of English throughout the code and comments.

@rafa11rodrigues

Copy link
Copy Markdown

Hi @avrilmai, thanks for pushing this forward from #53460!

Since it's been a couple of days, are you currently working on addressing @mlaurencin's feedback (relocating the tests to spec/, translating French comments/flags to English, and signing commits)?

As a screen reader user on Windows heavily impacted by #42945, I would be more than happy to adopt this branch, address the maintainer feedback, and open an updated PR so we can get this fix merged. Please let me know!

@rafa11rodrigues

Copy link
Copy Markdown

Adopted and continued in #56093 addressing the test location, English consistency, and signed commits feedback.

Thank you so much!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: NVDA screen reader no longer works since 30.0.0-beta.8

3 participants