Files
orca/src/shared/browser-composed-tree-script.ts
T
Kelvin AmoabaandFelipe 19c53e5248 fix(browser): let Grab page element pick and track elements inside open shadow roots (#34265)
* fix(browser): let Grab page element pick and track elements inside open shadow roots

Document hit-testing and marker lookups stop at a shadow host, so Grab only
ever picked the host. The overlay now descends through open shadow roots,
and both the overlay and the annotation viewport bridge find the marked
element and listen for scrolls inside them. Closed roots stay opaque.

Co-authored-by: Felipe <5784455+fbetancourtc@users.noreply.github.com>

* fix(browser): track slotted ancestors and stop re-walking shadow roots for a lost target

* fix(browser): walk shadow roots once per selection and count fixed shadow hosts

* fix(browser): restore grab pointer events if a page's shadowRoot throws; type the shadow fixtures

* fix(browser): keep composed-tree walks safe from page-named form controls

---------

Co-authored-by: Felipe <5784455+fbetancourtc@users.noreply.github.com>
2026-10-27 05:15:54 +00:00

21 lines
873 B
TypeScript

// Why: page-named form controls (e.g. <form name="host">) shadow DOM properties in the page's
// world, so each value is type-checked before the walk follows it.
export const COMPOSED_TREE_SCRIPT = ` function composedParent(element) {
var slot = element.assignedSlot;
if (slot && slot.localName === 'slot') return slot;
var parent = element.parentNode;
if (parent && parent.nodeType === 11) return parent.host || null;
return parent && parent.nodeType === 1 ? parent : null;
}
// Scroll events don't leave a shadow root, so trackers listen on each open root above the target.
function shadowRootsAbove(element) {
var roots = [];
for (var node = element; node; node = composedParent(node)) {
var parent = node.parentNode;
if (parent && parent.nodeType === 11 && parent.host) roots.push(parent);
}
return roots;
}
`