fix(web): render HTML files in file preview - #5112
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Needs human review This PR introduces a new feature that renders HTML files with JavaScript execution enabled in a sandboxed iframe. The security implications of executing user-provided scripts, even in a sandbox, warrant human review. You can customize Macroscope's approvability policy. Learn more. |
Opening an HTML workspace file currently shows source only, and served-web users cannot fall back to the Electron-only preview browser.
This adds the existing Source/Rendered toggle pattern to .html and .htm files. Rendered mode uses an iframe srcdoc sandbox that permits scripts while withholding same-origin access, forms, popups, top-level navigation, and downloads. Source remains the default, and line-reveal requests continue to select source mode.
Closes #5100
Screenshots
Verification
Built with GPT-5.6 Codex through the Codex harness in T3 Code.
Note
Render HTML files in the file preview panel with sandboxed iframe
isHtmlPreviewFileto detect.html/.htmfiles andprepareHtmlPreviewDocumentto rewrite the document's<base href>to the signed asset directory URL, enabling relative assets to resolve correctly in preview.RenderedHtmlSurfacecomponent that fetches the signed asset URL, prepares the HTML document, and renders it in a sandboxed iframe withreferrerPolicy=no-referrer.FilePreviewPanelwith a localStorage-backed toggle (t3code.renderHtml), sharing toggle UX with the existing Markdown render preference..html/.htmfiles now default to a rendered preview (iframe) rather than raw source; users can toggle back to source view.Macroscope summarized a63d845.
Note
Medium Risk
Sandboxed iframe preview runs authored scripts with
allow-scripts, which is intentional but still a security-sensitive surface; base URL rewriting touches served asset paths.Overview
Workspace
.html/.htmfiles can now switch between source and rendered preview, mirroring the existing markdown toggle. The preference is stored int3code.renderHtml; source stays the default, and line-reveal still forces source view.Rendered HTML is shown in a sandboxed iframe (
allow-scripts,no-referrer) viasrcDoc.prepareHtmlPreviewDocumentinjects or rewrites a<base href>so relative assets resolve against the signed workspace asset URL.Unit tests cover HTML file detection and base-tag preparation.
Reviewed by Cursor Bugbot for commit a63d845. Bugbot is set up for automated code reviews on this repo. Configure here.