fix(player): a picked File plays in WebKit when another site frames the page (#309)
Closes #309.
In WebKit (Safari, and every browser on iOS), a package given as a File now plays when the player's page is framed by another site. Before, it failed at bad-archive, "Could not read the archive index", so h5p-mcp-app's play page opened a tab in place of playing inside a ChatGPT reply.
Cause: a Service Worker under a cross-site frame in WebKit cannot read a Blob or File a page posts to it (NotFoundError: The object can not be found here.). It can read an ArrayBuffer, and Cache Storage the page wrote. Chromium and Firefox read all three. Measured with a minimal probe, and with the live play page nested as ChatGPT nests it.
Fix:
mount.ts: onfile, the worker reads one byte of the File. When it cannot, it answersunreadableand keeps nothing.h5p-offline-player.ts: onunreadable, the element has the Jobs worker store the File whole, as a download from a host withoutRangeis stored (downloading, thenindexing). The Jobs worker is the page's own, so it reads the File.jobs-worker.ts:downloadArchivetakes a picked file too, from the File. It resumes from the watermark and gives its own quota message.mount.tsandsource.ts: a picked file's stored copy is opened before the File is asked for, so a restarted worker needs noneed-fileeither.design/serving.md: the rule, in one bullet.
Tests:
cross-site-frame.test.ts(new): the element in a page framed from another host name plays a picked File. Before the fix it failed in WebKit with the error above; it passes now in Chromium, Firefox and WebKit.jobs-worker.test.ts: adownloadof a picked file stores it byte for byte, andopenSourcewith no File opens that copy.local-file.test.ts: with a stored copy, a File of the same id but blank bytes plays, so the copy is what is read. This runs in Chromium, as PR CI does.- Mutations caught: the worker asking for the File despite a stored copy fails both tests; the element ignoring
unreadablefails the WebKit one. - Full player suite in Chromium: 66 files, 598 tests. Browser suite in WebKit: 25 files, 191 tests. Slow files skipped in both.
After merging: a player patch and h5p-mcp-app, whose play page bundles the player, then the Worker deploy. The ChatGPT phone apps still open a tab: their web views give a framed page no Service Worker or no storage.
Summary by cubic
Fixes picked File playback in WebKit (Safari, iOS browsers) when the player's page is framed by another site, such as in a ChatGPT reply. Previously the load failed at bad-archive because a WebKit Service Worker under a cross-site frame cannot read a Blob or File posted to it, an error Chromium and Firefox do not hit.
- The Service Worker probes a handed File for readability and answers
unreadablewhen it cannot read it. - On
unreadable, the element has the Jobs worker store the whole File as a download is stored (downloading, thenindexing); the Jobs worker is the page's own, so it reads the File. - The Service Worker opens a picked file's stored copy before asking for the
File; a wait it is already in fails at once, and the page stores the copy then. - Added a cross-site-frame browser test that fails in WebKit without the fix; existing tests cover byte-for-byte storage and playback from the stored copy with a blank File of the same id.
No migration steps. After merging, roll out the player patch and the bundled h5p-mcp-app, then deploy the Worker. ChatGPT phone apps still open a tab: their web views give a framed page no Service Worker or storage.