fix: HTML artifact preview - serve endpoint replaces truncated srcDoc - #374
Open
dhb861832993-star wants to merge 2 commits into
Open
fix: HTML artifact preview - serve endpoint replaces truncated srcDoc#374dhb861832993-star wants to merge 2 commits into
dhb861832993-star wants to merge 2 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
srcDociframe.Root Cause
Backend truncation:
read_artifact()inmanager.pycaps text content at 500,000 characters. Large HTML files (e.g. those with inlined JS libraries like Three.js) are silently cut off.Frontend
srcDoc+sandbox: Loading HTML viasrcDocinto a sandboxed iframe gives it anullorigin, which prevents external CDN scripts from loading.Fix
Backend (
coworker/server/app.py)GET /v1/sessions/{id}/artifacts/serve?path=&token=FileResponseto stream the file directly — no truncation, no size limittokenas a query parameter (iframesrccannot set custom headers)Frontend (
surfaces/gui/src/api.ts+RightRail.tsx)artifactServeUrl()helper builds the serve URL with the auth tokensrc={serveUrl}instead ofsrcDoc={content}Changes
Only 3 files, 24 insertions, 2 deletions:
coworker/server/app.py— serve endpoint + query param authsurfaces/gui/src/api.ts—artifactServeUrl()helpersurfaces/gui/src/components/RightRail.tsx—srcreplacessrcDocTesting
tsc --noEmitpasses,npm run buildpassesSubmitted by: Haibo Dong