fix(web): drop zero-width spaces and soft hyphens from a name

GA
11h ago
+98-11

What

  • A name or label in the web tree drops U+200B and U+00AD, as Playwright does. <a href="…">Datenschutz&shy;erklärung</a> reads as link "Datenschutzerklärung", and toHaveAccessibleName('Datenschutzerklärung') holds for it.
  • getByRole and an exact getByLabel drop them from a string name the test passes, so a name copied from the page, hidden soft hyphen and all, still finds the control.

Why

getByRole found the link by the word a person reads, and toHaveAccessibleName on that same locator failed on the hidden character.

How it works

  1. withoutGlyphs, the exit every computed name and label goes through (packages/web/src/in-page/read-semantics.ts), drops the two characters after it turns icon glyphs into spaces.
  2. The title fallbacks (reportedName, the iframe in the tree walk) and the document title go through titleName, which drops only the two characters, so an icon glyph in a title is kept as on main. reportedName falls back to the title only when icon glyphs emptied the name: an aria-label="&#8203;" stays empty, as Playwright reads it.
  3. Query side: glyphTolerantName (locators.ts) drops them from a role name before it builds the pattern; the exact label projection and the in-page e2e-label engine (label-selector.ts) drop them from the label asked for.
  4. Tests: a crosscheck fixture, invisible characters (Playwright now agrees; Chrome keeps the characters, recorded in expected.txt with the reason, as for inert text), and cases in icon-glyph-names.test.ts for the tree name, a copied name in getByRole, an invisible-only aria-label, a title fallback, the document title, and an exact label alone and inside has.
  5. A paragraph under "Icon fonts and generated content" in docs/reference/web.mdx.

Out of scope: toHaveText / getByText, and the text passed to toHaveAccessibleName, which keeps the characters (the docs say so). Both go through core normalizeText, which every engine shares; whether it should drop them as Playwright's text normalization does is the question left for the maintainer in the review.

Issue

Fixes #2491

Verified

Ran it locally: yes

mainthis PR
tree name of Datenschutz&shy;erklärung"Datenschutz­erklärung""Datenschutzerklärung"
toHaveAccessibleName('Datenschutzerklärung')failspasses
getByRole('link', { name: 'Datenschutz­erklärung' })no match1 match
icon-glyph-names.test.ts with main's src4 of 7 fail7 of 7 pass

pnpm --filter @e2e-dev/web exec vitest run: 1282 tests pass. pnpm check passes.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Accessible names now omit zero-width spaces and soft hyphens. Names containing only these characters remain empty; icon-only names can still use a title fallback, which is normalized as well.
    • Role queries and exact label queries normalize zero-width spaces and soft hyphens in requested names and labels. Accessible-name assertions should omit these characters from expected values.
  • Documentation
    • Clarified how invisible characters affect accessible names, queries, labels, and accessible-name assertions.