mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1628] [CLOSED] frontend: Add preview of generated HTML and SVG #3569
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3569
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/1628
Author: @thoives
Created: 10/8/2026
Status: ❌ Closed
Base:
main← Head:main📝 Commits (1)
2e5e5d2Add preview of generated HTML or SVG📊 Changes
3 files changed (+112 additions, -8 deletions)
View changed files
📝
docs/DETAILS.md(+6 -2)📝
serve/web/app.js(+93 -6)📝
serve/web/components.css(+13 -0)📄 Description
Title
Issue: Resolves #1574
Also implements previewing generated SVGs - especially nice for mobile!
Summary
Adds a preview for generated SVG and HTML in the chat. A finished
svgorhtmlblock gets a preview button that flips between the code and a rendered picture or page. The preview is sandboxed, with no scripts and no network by default, follows the light or dark theme, and animates SVG in Chromium and Firefox. On an HTML page, the user can run that one block with scripts, after a warning.What changed
serve/web/app.jssandbox=""iframe (opaque origin: no scripts, forms, popups or navigation). A meta CSP (default-src 'none'; style-src 'unsafe-inline'; img-src data:) blocks the network. Blocks still streaming get no preview.previewDoc()):<!doctype html>page gets the CSP and theme first, then the page without its doctype. Its own html and head tags merge into ours, and its own CSS still wins.color-schemeand the ink color from--st-inkand has a transparent background, so it sits on the theme surface in both themes.setTheme()callsrefreshPreviews(), which rebuilds the frames that have been opened.<animate>,<animateTransform>) in a document where scripting is off, which is whatsandbox=""gives. A plain SVG is therefore shown as an<img>with a data URL (svgImage()), which runs no scripts, loads nothing, and animates. It is checked withDOMParserfirst, a missingxmlnsis added, and the theme ink is injected socurrentColorworks. If it is not well-formed XML, the inline SVG path is used.confirm()dialog. If accepted, only that block is rebuilt as a new iframe withsandbox="allow-scripts"(still an opaque origin) and a CSP that allows inline scripts but still no network. It is not remembered, and closing the preview turns it off again. The frame is created anew each time, because the sandbox attribute counts only when a frame is created.serve/web/components.css: styles for the button group, the pressed state, the preview box (hidden by default,min(340px,60vh)high, on--st-surface-2, transparent iframe), and an amber outline while scripts run.docs/DETAILS.md: the Chat bullet describes the preview, the theme, SVG animation, and the scripts button on HTML pages.Extra Notes
markdown()and click handler. A SMIL SVG gave 4 distinct frames over about a second in both browsers (static in Firefox before the image route). Scripts were off by default, ran only after confirming,fetch()was blocked, and they were off again after closing and reopening the preview. A script placed before<head>was blocked in safe mode. WebKit/Safari is untested because it would not launch here.<meta http-equiv=refresh>can still send the frame to a remote page, which would then run its own scripts in the sandbox. The CSP does not stop navigation, and this was not tested. The sandbox has no same-origin access, so it cannot read the chat or storage.<script>never runs it, because SVG previews use the image route and have no scripts button.🤖 Generated with Claude Code
Human: seems to work in Firefox with generated SVG (opaque and transparent) and HTML code.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.