mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-15 22:08:03 +00:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user