Skip to content

fix(aria): process children of hidden elements #36316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Skn0tt
Copy link
Member

@Skn0tt Skn0tt commented Jun 16, 2025

Closes #36296

@Skn0tt Skn0tt requested a review from Copilot June 16, 2025 08:05
@Skn0tt Skn0tt self-assigned this Jun 16, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses processing of hidden elements for ARIA snapshots in response to issue #36296. Key changes include:

  • Adding a new test to verify that visible children of hidden elements are correctly captured.
  • Introducing the helper function isVisible in the ARIA snapshot generation, and modifying text node and element handling accordingly.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/page/page-aria-snapshot.spec.ts Adds a test verifying that visible children within hidden elements are processed.
packages/injected/src/ariaSnapshot.ts Introduces a new isVisible helper function and updates element processing logic to incorporate it.
Comments suppressed due to low confidence (2)

packages/injected/src/ariaSnapshot.ts:50

  • Consider adding a brief comment above the isVisible function to explain its purpose in determining element visibility for ARIA processing.
function isVisible(element: Element, options?: { forAI?: boolean }): boolean {

tests/page/page-aria-snapshot.spec.ts:662

  • [nitpick] For consistency with other test names, consider renaming the test title to begin with 'should', for example: "should show visible children of hidden elements".
it('show visible children of hidden elements', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/36296' }  }, async ({ page }) => {

This comment has been minimized.

if (!isVisible)
if (!isVisible(element, options)) {
// skip this element, but still process its children: https://github.com/w3c/aria/issues/1055
processElement(ariaNode, element, []);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how this makes sense. Also, you can't process children as if they are visible. And we probably only want this for non-aria visibility.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how this makes sense

How so? As in, you're surprised how Chromium and this issue interpret the ARIA spec, or as in this code is weird?

Also, you can't process children as if they are visible.

I think we can, because the isVisible method takes parent elements into account when determining visibility.

we probably only want this for non-aria visibility.

It already does so, based on my reading of isElementHiddenForAria. I added a test in 9775c4a to ensure that.

This comment has been minimized.

@Skn0tt
Copy link
Member Author

Skn0tt commented Jun 24, 2025

As discussed yesterday, I scoped down the change to the AI snapshot.

@Skn0tt Skn0tt requested a review from pavelfeldman June 24, 2025 08:43

This comment has been minimized.

This comment has been minimized.

@@ -252,3 +252,16 @@ it('should auto-wait for blocking CSS', async ({ page, server }) => {
`, { waitUntil: 'commit' });
expect(await snapshotForAI(page)).toContainYaml('Hello World');
});

it('should show visible children of hidden elements', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/36296' } }, async ({ page }) => {
await page.setContent(`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this test a bit more involved:

- hidden
  - visible
    - neutral
  - hidden
    - visible
  - neutral (no visibility change)
    - visible
      - hidden
    - neutral

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 9584dc6

This comment has been minimized.

Copy link
Contributor

Test results for "tests 1"

1 failed
❌ [webkit-library] › library/browsercontext-viewport-mobile.spec.ts:97:5 › mobile viewport › should fire orientationchange event @webkit-ubuntu-22.04-node18

8 flaky ⚠️ [firefox-library] › library/inspector/cli-codegen-1.spec.ts:1070:7 › cli codegen record › should not throw csp directive violation errors @firefox-ubuntu-22.04-node18
⚠️ [firefox-page] › page/page-wait-for-function.spec.ts:104:3 › should work with strict CSP policy @firefox-ubuntu-22.04-node18
⚠️ [playwright-test] › ui-mode-test-output.spec.ts:80:5 › should show console messages for test @macos-latest-node18-1
⚠️ [playwright-test] › ui-mode-test-watch.spec.ts:145:5 › should watch all @ubuntu-latest-node22-1
⚠️ [playwright-test] › ui-mode-test-watch.spec.ts:145:5 › should watch all @ubuntu-latest-node24-1
⚠️ [webkit-page] › page/page-screenshot.spec.ts:345:5 › page screenshot › should work while navigating @webkit-ubuntu-22.04-node18
⚠️ [playwright-test] › ui-mode-test-output.spec.ts:80:5 › should show console messages for test @windows-latest-node18-1
⚠️ [playwright-test] › ui-mode-test-watch.spec.ts:145:5 › should watch all @windows-latest-node18-1

47019 passed, 983 skipped
✔️✔️✔️

Merge workflow run.

@Skn0tt Skn0tt requested a review from dgozman June 30, 2025 11:47
@@ -61,6 +69,9 @@ export function generateAriaTree(rootElement: Element, options?: { forAI?: boole
visited.add(node);

if (node.nodeType === Node.TEXT_NODE && node.nodeValue) {
if (node.parentElement && !isVisible(node.parentElement, options))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to solve it via a parameter boolean, that way you don't need to check parent visibility for every text child.

if (!isVisible(element, options)) {
if (options?.forAI)
// skip this element, but still process its children https://github.com/microsoft/playwright/issues/36296
processElement(ariaNode, element, []);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be consistent with the aria-owns children. We either respect them in forAI or we don't. Your change makes it inconsistent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say all we care about is that toAriaNode considers element as role === 'presentation' || role === 'none', then the right things will happen below.

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]: ariaSnapshot hides visibility: visible inside visibility: hidden
3 participants