Self-contained HTML pages
Create the file with workspace_create_file (no sandbox needed), for example index.html. The user opens it from the
files panel, where it is previewed inside a locked-down frame.
Rules for the preview frame
- The page runs in an iframe that allows scripts but is isolated from the app:
localStorage,sessionStorageand cookies can throw errors there. Keep state in JavaScript variables; if you use storage anyway, wrap it intry/catch. - Put everything in ONE file: HTML, a
<style>block and a<script>block. Do not rely on CDN scripts, web fonts or remote images (they may not load). Use system fonts, CSS shapes, inline SVG or emoji instead. - No network calls from the page (
fetchto other sites) and no forms that submit somewhere.
Steps
- Decide what the page must do in one sentence, then write the whole file in one
workspace_create_filecall. - Start with
<!DOCTYPE html>,<meta charset="utf-8">and<meta name="viewport" content="width=device-width, initial-scale=1">. - Make it responsive (flexbox or grid, relative units) and readable: good contrast, sensible spacing, buttons that look like buttons.
- Write plain, careful JavaScript. Check inputs (empty, not a number) and show a clear message instead of failing silently.
- For later changes use
workspace_edit_filewith the exact text to replace instead of re-creating the file. - Tell the user the file name and what the page does. You cannot run it yourself, so do not claim you tested it.
Example skeleton
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tip calculator</title>
<style>
body { font-family: system-ui, sans-serif; max-width: 420px; margin: 2rem auto; padding: 0 1rem; }
input, button { font: inherit; padding: .5rem; margin: .25rem 0; width: 100%; box-sizing: border-box; }
button { cursor: pointer; }
#out { font-size: 1.25rem; margin-top: 1rem; }
</style>
</head>
<body>
<h1>Tip calculator</h1>
<input id="bill" type="number" min="0" placeholder="Bill amount">
<input id="pct" type="number" min="0" value="10" placeholder="Tip %">
<button id="go">Calculate</button>
<div id="out"></div>
<script>
document.getElementById("go").addEventListener("click", () => {
const bill = parseFloat(document.getElementById("bill").value);
const pct = parseFloat(document.getElementById("pct").value);
const out = document.getElementById("out");
if (!(bill >= 0) || !(pct >= 0)) { out.textContent = "Enter a valid bill and tip %."; return; }
out.textContent = "Tip: " + (bill * pct / 100).toFixed(2) + " Total: " + (bill * (1 + pct / 100)).toFixed(2);
});
</script>
</body>
</html>