Skip to content

fix: a first play without Range boots in the package's language, and two worker states are read right - #59

Merged
alekswebnet merged 1 commit into
mainfrom
fix/first-play-manifest-and-worker-state
Oct 21, 2026
Merged

alekswebnet merged 1 commit into
mainfrom
fix/first-play-manifest-and-worker-state

Conversation

@alekswebnet

Copy link
Copy Markdown
Contributor

Closes #57.

Three defects in the player, found reviewing the changes of 2026-10-18 to 20. Each fix comes with a test that fails without it.

Changes

1. The manifest reaches the record when it arrives late (sw/mount.ts)

  • Before: on a host without Range, the worker opens its reader at the first progress report. When h5p.json was not in the first 256 kB, a later snapshot brought it in and refresh() saved nothing. The frame route reads the title, metadata and (since H5P's own strings follow the content's language #55) the language off the record. So the frame booted early in the element's language, untitled and with no licence, until a reload.
  • Now: refresh() saves the manifest to the record when a merged snapshot brings h5p.json in.

2. The registration found must be the element's own (h5p-offline-player.ts)

  • Before: stillRegistered accepted any live registration at the scope. After site data was cleared and another player or tab registered first, the element kept its old registration, which has no worker once its last client is gone. Every load then failed with no-worker until a reload.
  • Now: it also requires current === registration. If an engine ever handed out a new object for the same registration, the element would only register again on each load, which is harmless.

3. A sandboxed frame reports no-worker (h5p-offline-player.ts, docs/troubleshooting.md)

  • Before: in a frame sandboxed without allow-same-origin, 'serviceWorker' in navigator is true and reading the property throws a SecurityError in Chromium and WebKit. Checked in Playwright's three engines; Firefox returns the container. connectedCallback read it (?. doesn't catch a throw), so the element stopped before its load began and fired no error. The embed page then never showed its "open in its own tab" link.
  • Now: one helper, serviceWorkers(), reads the container and treats a throw as none. The element reads the property only through it. The load fails with no-worker, and the message names the sandbox. The troubleshooting table lists it.

Also

  • Three runtime comments said the core's strings follow the element's language; they follow the frame's, the content's first.
  • AGENTS.md records each fix beside the invariant it belongs to.

Testing

New tests, each run with and without its fix:

Test Without the fix
l10n.test.ts: german-late-manifest.h5p (new fixture: h5p.json behind 1 MB of media, 4 MB more after it), played without Range at 1 MB/s on an English page. It asserts the frame booted before the download finished, then lang="de", "Vollbild", the frame's title and the licence. expected 'en' to be 'de'
recovery.test.ts: a player's frame is emptied and its registration unregistered; a second player registers again; the first plays again. the load ends in an error
errors.test.ts: navigator.serviceWorker made to throw as in a sandboxed frame. network instead of no-worker, plus two uncaught SecurityErrors from connectedCallback

The second test empties the frame before unregistering. Unregistered while a frame was still its client, the registration was brought back by Chromium for the next register, which never reaches the bug.

Suites:

  • pnpm typecheck passes for the player and the runtime.
  • Unit tests: player 344 of 344, runtime 180 of 180.
  • Browser, Chromium: 190 of 190 plus the emulated project's 4.
  • Browser, Firefox and WebKit, the three changed files: 21 of 21 in each.
  • Demo app tests: 27 of 27; they cover the single-worker setup, where findMountedRoutes and the identity check now apply.
  • Embed: 26 of 26.

A flaky test to know about: worker-update.test.ts › "waits for the update however slow the script…" failed in 2 of 15 full Chromium runs on this branch, ending in under 4 s. On main it passed 3 of 3. On this branch it passes alone (4 of 4) and paired with each changed file (3 of 3 each). The path it exercises, a new element per test, does nothing different here. It has not failed in CI's last ten failed runs. My guess, unconfirmed: under a busier suite, the previous test's soft update is still running when installVersion calls update(), and that call joins it instead of installing 0.99.0. If CI hits it, re-run; hardening installVersion would be its own change.

Not verified:

  • The element inside a real sandboxed frame. The test stubs the getter; the engines' behaviour was checked separately with a plain page.
  • A real "Clear site data". The test reaches the same state through unregister() with no clients.
  • boardgame.h5p itself. The fixture reproduces its layout.

Release

A player patch (1.1.1). The runtime changes are comments only.

🤖 Generated with Claude Code

…two worker states are read right

- On a host without Range the worker opens its reader at the first
  progress report. When h5p.json was not among the first bytes, a later
  snapshot brought it in and nothing saved it to the record, which the
  frame route reads: the frame booted early in the element's language,
  untitled and unlicensed, until a reload. refresh() saves it now.
- stillRegistered took any live registration at the scope for the
  element's own. After site data was cleared and another player or tab
  registered first, the element kept posting to a registration with no
  worker, and every load failed with no-worker until a reload.
- In a frame sandboxed without allow-same-origin, reading
  navigator.serviceWorker throws in Chromium and WebKit. The element
  read it in connectedCallback and stopped before its load began, with
  no error event; it reports no-worker now.

Also corrects three runtime comments that still said the core's strings
follow the element's language.

Closes #57.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alekswebnet alekswebnet self-assigned this Oct 21, 2026
@alekswebnet
alekswebnet merged commit 206e3e6 into main Oct 21, 2026
8 checks passed
@alekswebnet
alekswebnet deleted the fix/first-play-manifest-and-worker-state branch October 21, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A first play without Range can boot in the wrong language, and two Service Worker states the element misreads

1 participant