---
name: web-contrib
description: "Contributing to the Kokoro-FastAPI web player: vanilla JS constraints, MSE/audio gotchas, unit and e2e test setup. Use when changing anything under web/."
title: web-contrib
canonical_url: https://skilld.dev/gh/remsky/kokoro-fastapi/web-contrib
last_updated: 2026-11-12T03:45:43.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install remsky/kokoro-fastapi/web-contrib`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/web-contrib`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/remsky/kokoro-fastapi/web-contrib) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/web-contrib`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/web-contrib --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/web-contrib --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

Read [AGENTS.md](../../../AGENTS.md) and [CONTRIBUTING.md](../../../CONTRIBUTING.md) first, house rules live there.

# Web player contributions

## Constraints

- Vanilla JS modules, no framework, no build step. Files under `web/src/` are served as-is by the API (`/web`).
- `web/src/services/AudioService.js` picks the playback path and owns the file-source swap. `services/audio/MsePipeline.js` is the bounded MSE (`audio/mpeg`) state machine, `services/audio/BlockLoader.js` the blob fallback where MSE mp3 is unsupported (Firefox). Any playback change must keep both paths working.
- Long-session behavior matters: the bounded buffer exists because unbounded MSE appends crashed ~10 min in. Don't reintroduce unbounded growth.
- A finished MSE stream swaps to the full server-side file so scrubbing and true duration work (`canSwapToFileSource` / `swapToFileSource`). Swaps only fire at existing discontinuities: end of playback, pause, seek, and read-along activation when no duration is known yet (`ReadAlong.js`). Don't trigger one mid-playback.

## Standard patterns

- Popup menus (`role="menu"`) get full keyboard support: ArrowUp/Down walk items with wrap, Escape closes and restores focus to the trigger, `focusout` closes when focus leaves, first item focused when opened via keyboard. Reference implementations: markup in `web/index.html` (`#cast-menu` is a `popover="manual"`, `#download-menu` is `hidden`-toggled), handlers in `VoiceSelector.js` and `App.js`. New menus copy that shape.
- File downloads go through `App.triggerDownload(url, name)`, don't hand-roll anchor clicks.
- Outside-click dismissal uses `closeOnOutsidePress` from `dismiss.js`.
- Fire-and-forget promises still need a `.catch` that surfaces via `showStatus`.
- Settings checkboxes copy `.autoplay-toggle` (player.css, plus its mobile media-query override): no `:hover` split, no per-control `accent-color`, `:root` in base.css sets it.
- Services take request values as arguments (`buildRequestBody(..., responseFormat)`). Read a control once in the caller, don't re-query it inside the service.

## Testing

- Unit: `npm run test:web` (node test runner). New test files go in `web/tests/unit/` and must be imported from `web/tests/unit/index.test.mjs`, it's a manual registry.
- E2e: `npm run test:e2e` (Playwright against `web/tests/e2e/fixtures/static-server.mjs` on port 4173, auto-started by the config). Stub the two startup calls with `mockApi(page)` from `fixtures/mock-api.mjs`, no TTS backend needed. CI runs unit and e2e on bundled Chromium.
- Bundled Chromium has no mp3 codec, so real MSE playback needs system Chrome: launch with `channel: 'chrome'` and skip when it's unavailable, CI has only bundled Chromium. `long-playback.spec.mjs` mocks `MediaSource` instead.
- For manual testing against a real backend, the cpu and gpu compose files already mount `web/` over the image's copy, edits are live per request. rocm needs the mount added.
- Before committing, check the change against [modern-web-guidance](https://developer.chrome.com/docs/modern-web-guidance) for current HTML/CSS/JS and accesibility patterns.
  