Skip to content

Allow video and audio in page media #1083

Closed

Description

@max-sixty

The case

An agent built a Leaf page that plays an animated, scrubbable explainer of Worktrunk's wt merge. A page module draws each frame as one SVG. A "Save as video" button replays the frames into a canvas and records them with MediaRecorder, which produced a valid H.264 MP4 (1280×720, ~30 fps, 35.4 s, 4.5 MB).

The next step was to put that recording back into a page as a <video>, so the explainer could be shown without its page module (in a summary page, a neighbouring page, or an export). Leaf refused it:

  • leaf page media <page> wt-merge.mp4 exits with not an image leaf serves, because cmd_media in skills/leaf/scripts/leaf/media.py admits only the suffixes in MEDIA_TYPES (schema.py): png, jpg/jpeg, gif, webp, svg.
  • Copying the file into media/ by hand wouldn't help either. The server's path allowlist is built from the same table (schema.py, the MEDIA_DIR pattern in DIR_FILES → SERVED_PATH), and SERVED_PATH.fullmatch("/media/0123456789abcdef.mp4") is False while the .png spelling is True, so the request 404s.

The page therefore had no supported way to show the video it had just made.

What video and audio in page media would take

I checked each of these in the code. Where I'm inferring rather than measuring, I say so.

  • Admitted types. Add .mp4 (video/mp4), .webm (video/webm) and probably .mp3/.m4a/.ogg for audio to MEDIA_TYPES. That one table feeds leaf page media, CONTENT_TYPES, BINARY_TYPES and SERVED_PATH, so admission and serving move together. The error text and docstrings ("not an image leaf serves", "Copy images into…") would read as media rather than images.
  • Sniffing. The browser upload door (store_uploaded_media) checks file signatures for four raster types. If uploads should accept video too, which is a separate decision, it needs signatures for ISO-BMFF (ftyp at offset 4) and WebM/Matroska (1A 45 DF A3). MAX_MEDIA_UPLOAD_BYTES (10 MiB) is sized for screenshots and would need a second look for video. The author door (cmd_media) trusts the suffix and needs no sniffing.
  • CSP. PAGE_CSP (structure.py) sets no media-src, so media falls back to default-src 'self' <CDN origins>. By the CSP spec a same-origin /media/…mp4 is already admitted, so I don't expect a policy change for served pages (inferred from the spec; not run, because the server refuses the path first).
  • Byte ranges. http.py serves a page file with read_bytes() and a single 200, with no Accept-Ranges or 206. Browsers usually play a 200 response, but seeking a <video> before it has fully buffered relies on range requests (Safari needs them to play at all). For a scrubbable explainer this matters, so serving media should support Range. I inferred this from browser behaviour and haven't measured it against Leaf's server.
  • Export. version export already handles most of this. resource_attribute_urls treats src and poster on any element except script/iframe as resources (so <video src>, <source src> and <audio src> are covered), and _embedded_policy already adds data: to media-src. What's missing is a size decision: inlining the 4.5 MB file above as base64 adds ~6 MB to the HTML, and a longer recording grows it without limit. Options: set a size cap with a clear refusal, or leave oversized media out of the export with a visible placeholder.
  • Guidance. references/authoring-evidence.md, "Source files and media", says to use leaf page media "for images". It would name video and audio, say when a recording is better than a live widget (a fixed demo, something for export, a screen capture of a real UI) and when it isn't (anything the user should manipulate or comment on frame by frame), and say to give a <video> controls and a poster.

Why it matters beyond this page

Many of the things an agent wants to show a user are motion: a UI interaction, a before/after that only differs in behaviour, a terminal session, a screen recording of a bug. Today the only options are a sequence of stills or a bespoke page module, and a module can't be reused on a page that doesn't have it. Pages already carry content-addressed media and export it, so video is the same mechanism with more types, plus byte ranges and an export size decision.

This was written by Claude Code on behalf of max-sixty

Activity

  1. leaf-agent commented on Sep 24, 2026

    @leaf-agent
    Collaborator

    This is a page-media feature request. The existing content-addressed path is the right place for authored recordings: MEDIA_TYPES controls both page media admission and the served-path allowlist, and captured page resources flow into export through revision_artifact.py. The current HTTP file response reads the complete file and returns 200, so seekable playback needs a range-response change in that same serving path.

    I would keep browser uploads a separate choice: store_uploaded_media currently accepts only signature-checked raster images with a 10 MiB limit, while page media accepts an author's local file by suffix. Export's inline_assets embeds referenced bytes, so a recording also needs an explicit export size policy. This would make a reusable recording work across pages while preserving the existing page-media ownership model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions