Skip to content

fix: return the shadow host for a text node in a shadow root in SerializedAXNode.elementHandle - #15451

Merged
samiyac merged 1 commit into
puppeteer:mainfrom
Dev-next-gen:fix/ax-text-in-shadow-root
Sep 15, 2026
Merged

samiyac merged 1 commit into
puppeteer:mainfrom
Dev-next-gen:fix/ax-text-in-shadow-root

Conversation

@Dev-next-gen

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bugfix.

Did you add tests for your changes?

Yes, a new case under Accessibility > elementHandle() in test/src/accessibility.test.ts.

If relevant, did you update the documentation?

Not needed, the documented return type (ElementHandle | null) doesn't change.

Summary

I was reading how SerializedAXNode.elementHandle() handles text nodes: it evaluates node.parentElement so that a StaticText node gives back its parent element. When the text sits directly inside a shadow root, parentElement is null (the parent node is the ShadowRoot), and evaluateHandle then returns a JSHandle wrapping null. That value isn't null and isn't an ElementHandle either, so the caller's null check passes and the next call blows up.

Repro against the current build, Chrome 153 headless:

await page.setContent(`<div id="host"></div>`);
await page.evaluate(() => {
  document.querySelector('#host').attachShadow({mode: 'open'}).textContent = 'shadow text';
});
const snapshot = await page.accessibility.snapshot({interestingOnly: false});
// find the StaticText node named 'shadow text'
const handle = await node.elementHandle();
// handle === null        -> false
// handle.constructor     -> CdpJSHandle
// handle.asElement()     -> null
// await handle.click()   -> TypeError: handle.click is not a function

The fix falls back to the shadow host when a text node has no parent element, which keeps the existing intent of the comment there (give the element that contains the text).

The new test fails on main with expect(received).toBeTruthy() Received: null on asElement(), and passes with the change. I ran the whole accessibility file on chrome-headless (32 passing) and the elementHandle() tests on chrome-bidi (3 passing); Firefox skips this file in TestExpectations.

Does this PR introduce a breaking change?

No. Text nodes with a parent element take the same path as before; only the case that currently returns an unusable handle changes.

Other information

AI tools used

@OrKoN
OrKoN requested a review from samiyac September 14, 2026 11:51
@samiyac
samiyac merged commit 101c7d5 into puppeteer:main Sep 15, 2026
41 checks passed
dadezzz pushed a commit to dadezzz/events-cash-register that referenced this pull request Sep 27, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [puppeteer-core](https://github.com/puppeteer/puppeteer/tree/main#readme) ([source](https://github.com/puppeteer/puppeteer)) | [`25.11.0` → `25.12.0`](https://renovatebot.com/diffs/npm/puppeteer-core/25.11.0/25.12.0) | ![age](https://developer.mend.io/api/mc/badges/age/npm/puppeteer-core/25.12.0?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/puppeteer-core/25.11.0/25.12.0?slim=true) |

---

### Release Notes

<details>
<summary>puppeteer/puppeteer (puppeteer-core)</summary>

### [`v25.12.0`](https://github.com/puppeteer/puppeteer/releases/tag/puppeteer-core-v25.12.0): puppeteer-core: v25.12.0

[Compare Source](puppeteer/puppeteer@puppeteer-core-v25.11.0...puppeteer-core-v25.12.0)

##### 🎉 Features

- roll to Chrome 154.0.8037.57 ([#&#8203;15484](puppeteer/puppeteer#15484)) ([00eec77](puppeteer/puppeteer@00eec77))
- roll to Firefox 156.0 ([#&#8203;15464](puppeteer/puppeteer#15464)) ([abdc078](puppeteer/puppeteer@abdc078))

##### 🛠️ Fixes

- **launcher:** clean temporary profiles on process exit ([#&#8203;15441](puppeteer/puppeteer#15441)) ([b30d91c](puppeteer/puppeteer@b30d91c))
- release the mouse button when a drag or drop fails ([#&#8203;15231](puppeteer/puppeteer#15231)) ([469621f](puppeteer/puppeteer@469621f))
- return the shadow host for a text node in a shadow root in SerializedAXNode.elementHandle ([#&#8203;15451](puppeteer/puppeteer#15451)) ([101c7d5](puppeteer/puppeteer@101c7d5))
- roll to Chrome 153.0.8010.47 ([#&#8203;15465](puppeteer/puppeteer#15465)) ([1ce3a9a](puppeteer/puppeteer@1ce3a9a))
- roll to Chrome 153.0.8010.52 ([#&#8203;15470](puppeteer/puppeteer#15470)) ([257a6a1](puppeteer/puppeteer@257a6a1))
- roll to Firefox 156.0.1 ([#&#8203;15483](puppeteer/puppeteer#15483)) ([73d8fec](puppeteer/puppeteer@73d8fec))

##### Dependencies

- The following workspace dependencies were updated
  - dependencies
    - [@&#8203;puppeteer/browsers](https://github.com/puppeteer/browsers) bumped from 3.2.2 to 3.2.3

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMTUuMTAiLCJ1cGRhdGVkSW5WZXIiOiI0NC4xMTUuMTAiLCJ0YXJnZXRCcmFuY2giOiJtYWluIiwibGFiZWxzIjpbXX0=-->
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.

2 participants