preview_frame() embeds a live web page served from an explicitly approved second origin (such as a compiled docs staging host or a local dev server) inside a restrictive sandbox while preserving parent navigation isolation.
preview_frame()
Unlike html() (which renders inline HTML inside a constrained srcDoc frame), preview_frame() loads a real URL so themed stylesheets, scripts, and relative assets resolve against that origin.
html()
srcDoc
In a React plugin using <BlockTree>:
<BlockTree>
allowed_origins
http(s)://host[:port]
"*"
javascript:
data:
<iframe>
allow-scripts allow-same-origin allow-forms
allow-top-navigation
allow-popups-to-escape-sandbox
Content-Security-Policy
create_shell_app(..., csp={"frame-src": ["http://127.0.0.1:4173"]})
frame-src
rel="noopener noreferrer"
load
| Parameter | Type | Default | Description |
|---|---|---|---|
| url | str | required | Absolute http(s):// URL to frame |
url
str
http(s)://
| allowed_origins | list[str] | required | Approved http(s)://host[:port] origins (no wildcards) |
list[str]
| title | str | "Site preview" | Accessible iframe title and header label |
title
"Site preview"
| height | str \| int | "640px" | Frame height (px, vh, rem, %, or pixel int 120–4000) |
height
str \| int
"640px"
px
vh
rem
%
120–4000
| viewport | "desktop" \| "tablet" \| "mobile" | "desktop" | Initial viewport preset (100%, 768px, 390px) |
viewport
"desktop" \| "tablet" \| "mobile"
"desktop"
100%
768px
390px
| sandbox | str \| None | "allow-scripts allow-same-origin allow-forms" | Optional sandbox flags (top-navigation tokens are stripped) |
sandbox
str \| None
"allow-scripts allow-same-origin allow-forms"
| open_in_new_tab | bool | True | Show external link button in frame header |
open_in_new_tab
bool
True
| viewport_controls | bool | True | Show Desktop / Tablet / Mobile viewport toggle buttons |
viewport_controls