Repository navigation
feat(canvas): export widgets as PNG — copy or download from the card menu - #110992
Conversation
|
Proof — the sandboxed frame rasterizing itself: standalone harness served the wrapped document in a |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fb0c6d9028
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| void blob.catch(() => {}); | ||
| // Start the permission-gated write while the menu selection still carries | ||
| // transient user activation; ClipboardItem resolves the PNG afterward. | ||
| return navigator.clipboard.write([new ClipboardItem({ "image/png": blob })]); |
There was a problem hiding this comment.
Gate image copy on Clipboard API availability
On supported plain-HTTP/LAN Control UI deployments, navigator.clipboard is intentionally unavailable, as documented by the existing fallback in ui/src/lib/clipboard.ts:3-7. This unconditional call therefore throws before copying anything, while the new menu still advertises the action and only shows a generic failure toast. Gate the image-copy action on both navigator.clipboard.write and ClipboardItem, or present an explicit unsupported-state message.
Useful? React with 👍 / 👎.
| const url = new URL(src, window.location.href); | ||
| if (url.origin !== window.location.origin) { | ||
| throw new Error("widget document URL is not same-origin"); | ||
| } |
There was a problem hiding this comment.
Preserve legacy downloads on scoped Canvas hosts
When hello.pluginSurfaceUrls.canvas is present, chat-pane.ts passes it into widget rendering and resolveCanvasIframeUrl deliberately rewrites the iframe to a different scoped origin (the established case is covered in ui/src/pages/chat/components/chat-message.test.ts:3092-3124). For an older widget without the snapshot bridge, the timeout reaches this guard, which always rejects that cross-origin iframe URL, so Download file shows an error instead of providing the documented HTML fallback. The legacy path needs to download through the scoped Canvas route or otherwise handle this supported topology.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 275089f83c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| timeoutMs, | ||
| ); | ||
| try { | ||
| target.postMessage({ type: WIDGET_SNAPSHOT_REQUEST_TYPE, id }, "*"); |
There was a problem hiding this comment.
Wait for the iframe load before requesting a snapshot
When the user opens the menu before the iframe finishes navigating—especially with a slow or scoped Canvas host—contentWindow already exists but the snapshot bridge has not installed its listener, so this one-shot message is lost. Five seconds later the current widget is misclassified as legacy: copy requests a re-render and download falls back to HTML. Disable the actions until the frame's load event or queue/retry the request after load.
Useful? React with 👍 / 👎.
| 'const data=event.data;if(!data||data.type!=="openclaw:widget-snapshot-request"||typeof data.id!=="string")return;' + | ||
| "void (async()=>{try{const body=document.body;" + | ||
| "const width=max(1,body.scrollWidth);const height=max(1,body.scrollHeight);" + | ||
| 'const root=clone.call(document.documentElement,true);const scripts=query.call(root,"script");' + |
There was a problem hiding this comment.
Preserve shadow-root content in widget snapshots
For a valid widget that renders a custom element through attachShadow(), cloneNode(true) does not copy the default non-clonable shadow root, and the subsequent script removal prevents the serialized document from recreating it. The exported PNG therefore omits the component's rendered content—often leaving an empty host—even though the iframe displays it; materialize shadow-root contents into the snapshot tree or explicitly handle unsupported shadow-based widgets.
Useful? React with 👍 / 👎.
275089f to
557e002
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 557e00225d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| function renderWidgetActions(preview: ToolPreview) { | ||
| if (preview.mcpApp || !isInternalCanvasEntryUrl(preview.url)) { | ||
| return nothing; | ||
| } |
There was a problem hiding this comment.
Hide snapshot actions when scripts are disabled
With the documented gateway.controlUi.embedSandbox: "strict" setting, resolveEmbedSandbox(..., "scripts") gives this widget iframe an empty sandbox, so the newly injected snapshot bridge never executes. This guard still exposes both actions for every internal Canvas widget: Copy waits five seconds and permanently claims the widget needs re-rendering, while Download incorrectly takes the legacy HTML fallback even for a newly rendered widget. Gate the PNG actions on the effective sandbox or provide an export path that does not require iframe scripts.
Useful? React with 👍 / 👎.
| 'const data=event.data;if(!data||data.type!=="openclaw:widget-snapshot-request"||typeof data.id!=="string")return;' + | ||
| "void (async()=>{try{const body=document.body;" + | ||
| "const width=max(1,body.scrollWidth);const height=max(1,body.scrollHeight);" + | ||
| 'const root=clone.call(document.documentElement,true);const scripts=query.call(root,"script");' + |
There was a problem hiding this comment.
Materialize live form values before serializing
When an interactive widget contains an input, textarea, select, checkbox, or similar control that the user has changed, its current state lives in DOM properties rather than the original serialized attributes or text. Cloning and then passing the clone directly to XMLSerializer therefore renders the control's default state into the SVG, so the exported PNG does not match the visible widget. Copy live values, checked states, and selections into serializable markup before creating the SVG.
Useful? React with 👍 / 👎.
|
Codex review: needs real behavior proof before merge. Reviewed July 18, 2026, 7:16 PM ET / 23:16 UTC. Summary PR surface: Source +313, Tests +179, Docs +3. Total +495 across 9 files. Reproducibility: yes. from source: strict embed sandbox disables the bridge while actions remain available, and interactive form values are not represented by direct DOM serialization; the supplied browser harness also establishes the snapshot request/reply path. Review metrics: none identified. Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Mantis proof suggestion Risk before merge
Maintainer options:
Next step before merge
Maintainer decision needed
Security Review findings
Review detailsBest possible solution: Gate or clearly downgrade PNG actions when the effective sandbox cannot execute the bridge, materialize live form control state before serialization, and provide redacted browser proof of both card-menu export actions. Do we have a high-confidence way to reproduce the issue? Yes, from source: strict embed sandbox disables the bridge while actions remain available, and interactive form values are not represented by direct DOM serialization; the supplied browser harness also establishes the snapshot request/reply path. Is this the best way to solve the issue? Unclear: self-rasterization inside the opaque-origin frame is a reasonable boundary-preserving approach, but it is not complete until unavailable sandbox modes and live widget state are handled correctly. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 2dce9d301220. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +313, Tests +179, Docs +3. Total +495 across 9 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
557e002 to
8d629dd
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8d629dd846
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (preview.mcpApp || !isInternalCanvasEntryUrl(preview.url)) { | ||
| return nothing; | ||
| } |
There was a problem hiding this comment.
Restrict export actions to snapshot-enabled widget documents
For a Canvas preview targeting /__openclaw__/a2ui/... or another non-document Canvas-host path, this predicate still exposes the export menu because isInternalCanvasEntryUrl accepts the entire Canvas and A2UI path families (ui/src/lib/chat/tool-display.ts:151-157). Only documents created by buildWidgetDocument receive the snapshot bridge (src/canvas/wrap.ts:201), so copying these previews always waits five seconds and reports a rerender requirement that can never help, while downloading falls back to the host application's HTML shell. Restrict this action to the /__openclaw__/canvas/documents/... surface or an explicit snapshot capability.
Useful? React with 👍 / 👎.
| "const canvasWidth=ceil(width*scale);const canvasHeight=ceil(height*scale);" + | ||
| 'if(canvasWidth>16384||canvasHeight>16384||canvasWidth*canvasHeight>16777216)throw new ErrorCtor("widget snapshot dimensions exceed limit");' + |
There was a problem hiding this comment.
Bound snapshots by their encoded PNG size
For a high-entropy 4096×4096 widget, this 16,777,216-pixel limit permits the capture even though its PNG can approach 64 MiB before base64 expansion; the receiver then rejects any data URL above 32 MiB (ui/src/pages/chat/components/widget-export.ts:4). The bridge therefore performs the expensive encode and posts a very large message only for both export actions to end in the generic failure toast. Downscale the capture or enforce a pixel/encoded-size limit that guarantees the generated PNG satisfies the receiver's bound.
Useful? React with 👍 / 👎.
|
Merged via squash.
|
…menu (openclaw#110992) * feat(canvas): export widgets as PNG — copy to clipboard or download from the card menu * fix(ui): widget-export lint, knip, and lines-budget cleanup
…menu (openclaw#110992) * feat(canvas): export widgets as PNG — copy to clipboard or download from the card menu * fix(ui): widget-export lint, knip, and lines-budget cleanup

What Problem This Solves
Widgets rendered by
show_widgetin web chat are view-only. Users who want to share or keep what the agent drew screenshot the page manually. The frame is opaque-origin sandboxed, so the Control UI cannot rasterize it from outside.Why This Change Was Made
Widget cards get a "…" actions menu (reusing the existing
wa-dropdownpattern) with "Copy to clipboard" and "Download file", both producing a PNG of the rendered widget.Mechanism: a fourth wrapper bridge (
src/canvas/wrap.ts) answers parent-only snapshot requests by serializing the live document into an SVGforeignObject(scripts stripped from the clone, live canvases preserved as images), drawing it onto a canvas prefilled with the computed--surfacecolor at capped devicePixelRatio, and replying with a PNG data URL. CSP untouched — onlydata:images are used. The bridge snapshots every primitive at parse time like the existing three bridges; replies go only towindow.parent, and the parent validates id, source, PNG prefix, and a 32 MiB cap (ui/src/pages/chat/components/widget-export.ts).Fallbacks for legacy documents without the bridge (5s timeout): Download falls back to the raw HTML document; Copy explains the widget needs re-rendering. Copy path uses
ClipboardItemwithin the user-gesture chain. Menu, aria, toast, and error copy routed through the i18n catalog.User Impact
Any widget in web chat can be copied as an image or downloaded as
<title>.pngfrom its card menu. Old widgets degrade gracefully.Evidence
node scripts/run-vitest.mjs src/canvas/widget-tool.test.ts— 5 passed (bridge presence/order, updated wrapper byte pin).node scripts/run-vitest.mjs ui/src/pages/chat/components/export/card tests — 7 passed (reply matching, validation, filenames, clipboard timing, fallbacks).sandbox="allow-scripts"iframe with the same CSP; the snapshot request returned a 760×363 PNG whose pixels match the rendered widget (screenshot in PR comment). This harness caught and confirmed the fix for a cross-interfaceIllegal invocationin the initial bridge implementation.gpt-5.6-sol): four findings accepted and fixed; one rejected (proposed replacing the reviewed request/reply protocol with a MessageChannel — contract-changing alternative, existing protocol validates source + id + payload).Release-note context:
feat: copy or download any web-chat widget as a PNG from its card menu.