Skip to content

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

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

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

Conversation

@avrilmai

@avrilmai avrilmai commented Oct 25, 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). 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. 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 a 40x40 child view
in the corner of the content view.

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 on a text resolves to role=16 (ROLE_SYSTEM_PANE), with
    no name, that is the empty content view. A screen reader on the legacy path
    has nothing to announce.

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.

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.
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.
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.
@welcome

welcome Bot commented Oct 25, 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 was automatically closed because the PR template was not properly filled out. The following required sections are missing:

  • #### Description of Change
  • #### Checklist

Please update your PR description to include all required sections and reopen the PR.

@github-actions github-actions Bot closed this Oct 25, 2026
@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.

@github-actions github-actions Bot added the needs-signed-commits Currently some or all of the commits in this PR are not signed label Oct 25, 2026
@avrilmai

Copy link
Copy Markdown
Author

This pull request was closed automatically by the template check a few seconds after it was opened: the description did not contain the #### Description of Change and #### Checklist sections that .github/PULL_REQUEST_TEMPLATE.md defines.

The description has since been corrected (it now contains the three sections of the template, and it is the description of #55334). GitHub however refuses to reopen this pull request (reopenPullRequest returns an error), so the same branch is proposed again in #55334:

#55334

The commits are unchanged since this pull request was opened.

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

Labels

needs-signed-commits Currently some or all of the commits in this PR are not signed

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

1 participant