test(studio): walk open shadow roots to the preview iframe in the flash controls and input log

The previous commit only switched the frame check to the live URL; the iframe walk did not land.
This commit is contained in:
Miguel Ángel
2026-09-30 19:54:28 -04:00
parent 07b3043919
commit 2e83db5a4b
2 changed files with 11 additions and 4 deletions
@@ -655,9 +655,11 @@ function injectControl(page) {
return "";
}
};
const frames = [...document.querySelectorAll("iframe")].filter((f) =>
url(f).includes("/preview"),
);
const iframes = (root) =>
[...root.querySelectorAll("*")].flatMap((el) =>
el.tagName === "IFRAME" ? [el] : el.shadowRoot ? iframes(el.shadowRoot) : [],
);
const frames = iframes(document).filter((f) => url(f).includes("/preview"));
const area = (f) => f.offsetWidth * f.offsetHeight;
frames.reduce((a, b) => (area(b) > area(a) ? b : a)).contentWindow.location.reload();
});
@@ -21,12 +21,17 @@ function markerOn() {
if (e.type === "pointerup" || !MODIFIERS.has(e.key))
marker.inputs.push({ type: e.type, key: e.key ?? null, n: marker.n, t: performance.now() });
};
// Studio's preview iframe sits in the player's shadow root, out of querySelectorAll's reach.
const iframes = (root) =>
[...root.querySelectorAll("*")].flatMap((el) =>
el.tagName === "IFRAME" ? [el] : el.shadowRoot ? iframes(el.shadowRoot) : [],
);
const listen = (w) => {
for (const type of ["pointerup", "keydown"]) {
w.addEventListener(type, log, true);
marker.unlisten.push(() => w.removeEventListener(type, log, true));
}
for (const f of w.document.querySelectorAll("iframe")) {
for (const f of iframes(w.document)) {
try {
listen(f.contentWindow);
} catch {