Skip to content

Commit fca0cec

Browse files
fix(player): a sealed film is no longer offered fullscreen (#8910)
* fix(player): a sealed film is no longer offered fullscreen The player's frame allowed fullscreen for every film. Every fullscreen request the player and Studio make targets the player or Studio's own page, never the film, so a sealed (opaque-origin) film now gets "autoplay" only; an unsealed film keeps "autoplay; fullscreen". * test(player): the sandbox tests only read messages from the player's own frame
1 parent 7dfe2c2 commit fca0cec

6 files changed

Lines changed: 77 additions & 7 deletions

File tree

‎docs/packages/player.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ The composition runs in a sandboxed iframe inside the player's Shadow DOM. This
225225
isolates its styles, scales it to the player container, and lets the player
226226
communicate with the HyperFrames runtime through `postMessage`. Set
227227
`sandbox-origin="opaque"` to seal the frame, so the composition cannot read
228-
your page or its cookies. The player adds the runtime itself to a composition
228+
your page or its cookies, or take the screen with fullscreen; the player's own
229+
fullscreen button still works. The player adds the runtime itself to a composition
229230
from your own site; a composition from another site must include the runtime
230231
script.
231232

‎packages/player/src/hyperframes-player.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4258,6 +4258,14 @@ describe("HyperframesPlayer retained runtime data", () => {
42584258
expect(player.iframeElement.sandbox.contains("allow-same-origin")).toBe(true);
42594259
});
42604260

4261+
it("offers fullscreen to an unsealed film only", () => {
4262+
expect(player.iframeElement.allow).toBe("autoplay; fullscreen");
4263+
player.setAttribute("sandbox-origin", "opaque");
4264+
expect(player.iframeElement.allow).toBe("autoplay");
4265+
player.removeAttribute("sandbox-origin");
4266+
expect(player.iframeElement.allow).toBe("autoplay; fullscreen");
4267+
});
4268+
42614269
it("names its frame, the one mark a composition in an opaque sandbox can still read", () => {
42624270
player.setAttribute("sandbox-origin", "opaque");
42634271
expect(player.iframeElement.name).toBe(PLAYER_FRAME_NAME);

‎packages/player/src/hyperframes-player.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,9 @@ class HyperframesPlayer extends HTMLElement {
446446
}
447447

448448
private _applySandboxOriginPolicy(reloadActiveDocument = false): void {
449-
if (this.hasAttribute(SANDBOX_ORIGIN_ATTR)) {
450-
this.iframe.sandbox.remove("allow-same-origin");
451-
} else {
452-
this.iframe.sandbox.add("allow-same-origin");
453-
}
449+
const sealed = this.hasAttribute(SANDBOX_ORIGIN_ATTR);
450+
this.iframe.sandbox.toggle("allow-same-origin", !sealed);
451+
this.iframe.allow = sealed ? "autoplay" : "autoplay; fullscreen";
454452
if (reloadActiveDocument) this._reloadForSandboxOriginPolicy();
455453
}
456454

‎packages/player/src/iframe-dom.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export function createCompositionIframe(): {
4848
const iframe = document.createElement("iframe");
4949
iframe.className = "hfp-iframe";
5050
iframe.sandbox.add("allow-scripts", "allow-same-origin");
51-
iframe.allow = "autoplay; fullscreen";
5251
iframe.referrerPolicy = "same-origin";
5352
iframe.title = "HyperFrames Composition";
5453
iframe.setAttribute(PLAYER_FRAME_ATTR, "");

‎packages/player/tests/browser/sandbox-origin.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,11 @@ try {
214214
// fails without the fix: the old document's timeline, landing after a switch, made the new load skip its probe.
215215
const switched = await browser.newPage();
216216
await switched.evaluateOnNewDocument(() => {
217+
const playerFrame = () =>
218+
document.querySelector("hyperframes-player")?.shadowRoot?.querySelector("iframe")
219+
?.contentWindow;
217220
addEventListener("message", (event) => {
221+
if (event.source !== playerFrame()) return;
218222
const data = event.data as { source?: string; type?: string } | null;
219223
if (data?.source === "hf-preview" && data.type === "timeline")
220224
(window as { __lastTimeline?: unknown }).__lastTimeline = data;
@@ -256,6 +260,46 @@ try {
256260
lateError,
257261
"a sealed player switched to a film with no runtime must fail, even after a late old timeline",
258262
);
263+
// fails without the fix: a click inside a sealed film let the film take the screen.
264+
const fullscreenAfterClick = async (sealed: boolean) => {
265+
const page = await browser.newPage();
266+
await page.evaluateOnNewDocument(() => {
267+
const playerFrame = () =>
268+
document.querySelector("hyperframes-player")?.shadowRoot?.querySelector("iframe")
269+
?.contentWindow;
270+
const w = window as { __fullscreen?: string[] };
271+
w.__fullscreen = [];
272+
addEventListener("message", (event) => {
273+
if (event.source !== playerFrame()) return;
274+
if (event.data?.source === "hf-fullscreen-probe") w.__fullscreen!.push(event.data.result);
275+
});
276+
});
277+
await page.goto(
278+
`${server.origin}/host.html?fixture=fullscreen-probe${sealed ? "&sealed=1" : ""}`,
279+
{ waitUntil: "domcontentloaded" },
280+
);
281+
const results = () => page.evaluate(() => (window as { __fullscreen?: string[] }).__fullscreen);
282+
await page.waitForFunction(() =>
283+
(window as { __fullscreen?: string[] }).__fullscreen?.includes("loaded"),
284+
);
285+
await page.evaluate(() =>
286+
document.querySelector("hyperframes-player")!.setAttribute("interactive", ""),
287+
);
288+
const box = await (await page.$("hyperframes-player"))!.boundingBox();
289+
await page.mouse.click(box!.x + box!.width / 2, box!.y + box!.height / 2);
290+
await page.waitForFunction(
291+
() => ((window as { __fullscreen?: string[] }).__fullscreen?.length ?? 0) >= 2,
292+
);
293+
const result = (await results())!.at(-1);
294+
await page.close();
295+
return result;
296+
};
297+
assert.equal(await fullscreenAfterClick(false), "granted", "an unsealed film keeps fullscreen");
298+
assert.notEqual(
299+
await fullscreenAfterClick(true),
300+
"granted",
301+
"a click inside a sealed film must not let it go fullscreen",
302+
);
259303
} finally {
260304
await browser.close();
261305
await server.stop();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Fullscreen probe</title>
6+
</head>
7+
<body style="margin: 0; width: 100vw; height: 100vh">
8+
<script>
9+
const report = (result) =>
10+
window.parent.postMessage({ source: "hf-fullscreen-probe", result }, "*");
11+
addEventListener("pointerdown", () =>
12+
document.documentElement.requestFullscreen().then(
13+
() => report("granted"),
14+
(error) => report(error.name),
15+
),
16+
);
17+
report("loaded");
18+
</script>
19+
</body>
20+
</html>

0 commit comments

Comments
 (0)