Skip to content

fix: HTML artifact preview - serve endpoint replaces truncated srcDoc - #374

Open
dhb861832993-star wants to merge 2 commits into
andrewyng:mainfrom
dhb861832993-star:fix/html-artifact-preview
Open

fix: HTML artifact preview - serve endpoint replaces truncated srcDoc#374
dhb861832993-star wants to merge 2 commits into
andrewyng:mainfrom
dhb861832993-star:fix/html-artifact-preview

Conversation

@dhb861832993-star

Copy link
Copy Markdown

Problem

HTML artifacts larger than 500KB are truncated and fail to render in the right-rail preview panel. Additionally, CDN-hosted scripts (e.g. Three.js) cannot load inside the sandboxed srcDoc iframe.

Root Cause

  1. Backend truncation: read_artifact() in manager.py caps text content at 500,000 characters. Large HTML files (e.g. those with inlined JS libraries like Three.js) are silently cut off.

  2. Frontend srcDoc + sandbox: Loading HTML via srcDoc into a sandboxed iframe gives it a null origin, which prevents external CDN scripts from loading.

Fix

Backend (coworker/server/app.py)

  • New endpoint: GET /v1/sessions/{id}/artifacts/serve?path=&token=
  • Uses FastAPI FileResponse to stream the file directly — no truncation, no size limit
  • Auth middleware now also accepts token as a query parameter (iframe src cannot set custom headers)
  • MIME type detection for common web assets (HTML, CSS, JS, images, JSON, SVG)

Frontend (surfaces/gui/src/api.ts + RightRail.tsx)

  • New artifactServeUrl() helper builds the serve URL with the auth token
  • HTML artifacts use src={serveUrl} instead of srcDoc={content}
  • The iframe gets a proper HTTP origin, so CDN scripts and inlined scripts both load correctly

Changes

Only 3 files, 24 insertions, 2 deletions:

  • coworker/server/app.py — serve endpoint + query param auth
  • surfaces/gui/src/api.tsartifactServeUrl() helper
  • surfaces/gui/src/components/RightRail.tsxsrc replaces srcDoc

Testing

  • Verified with a 6.2MB HTML file (Three.js inlined) — renders correctly in the right-rail panel
  • Verified with CDN-based HTML — external scripts now load in the sandbox
  • tsc --noEmit passes, npm run build passes

Submitted by: Haibo Dong

BOBO added 2 commits July 31, 2026 20:42
Problem: HTML artifacts larger than 500KB are truncated by read_artifact()
and fail to render in the right-rail preview. CDN scripts also cannot load
in a sandboxed srcDoc iframe (null origin).

Fix:
- Backend: new GET /v1/sessions/{id}/artifacts/serve endpoint streams files
  via FileResponse (no truncation, no size limit)
- Backend: auth middleware accepts token as query param (iframe src cannot
  set custom headers)
- Frontend: HTML artifacts use src={serveUrl} instead of srcDoc={content},
  giving the iframe a proper HTTP origin so external scripts load correctly

Submitted by: Haibo Dong
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.

1 participant