# Iframe Sandbox Canvas Performance Impact Report ## Executive Summary When a web page runs inside an ` ``` This is **missing `allow-same-origin`**, which causes: 1. Content treated as opaque/cross-origin to itself 2. Canvas security checks activate on every pixel operation 3. Browser may fall back to software rendering 4. ~50% FPS drop observed **Solution**: Users must enable "Advanced Mode" on objkt.com, which adds `allow-same-origin`. --- ## Affected KidLisp Features The `$roz` code uses these operations that suffer in sandboxed contexts: | Feature | KidLisp Command | Canvas Operation | Impact | |---------|-----------------|------------------|--------| | Render | (every frame) | `putImageData` | ⚠️ 50% slower | | Scroll | `scroll` | Reads/writes pixels | ⚠️ Slower | | Contrast | `contrast` | Pixel manipulation | ⚠️ Slower | | Color parsing | `ink`, `fade` | `getImageData` (fallback) | ⚠️ Potential slowdown | --- ## Implemented Optimizations ### ✅ Sandbox Detection (bios.mjs) Added early detection of opaque origin (sandboxed iframe without `allow-same-origin`): ```javascript // Detects objkt.com's sandbox="allow-scripts allow-downloads" const isOpaqueOrigin = (() => { try { if (window.origin === 'null') return true; localStorage.getItem('__sandbox_test__'); return false; } catch (e) { return true; } })(); // Exposed globally for pieces to detect globalThis.acIsSandboxed = isOpaqueOrigin; ``` ### ✅ Canvas Context Hints (bios.mjs) Added `willReadFrequently: true` hint to all canvas contexts when in sandboxed mode: | Canvas | Line | Purpose | |--------|------|---------| | `ctx` (main) | ~936 | Primary render target - **already had hint** | | `uiCtx` | ~1025 | UI overlay | | `debugCtx` | ~1029 | Debug overlay | | `ffCtx` | ~1036 | Freeze frame buffer | | `octx` | ~1041 | Corner label overlay | | `dirtyBoxCtx` | ~1045 | Dirty box updates | | `glazeCompositeCtx` | ~1061 | Glaze compositing | | `coerceToRGB.ctx` | ~1306 | Color parsing - **already had hint** | This tells the browser to use software rendering from the start, avoiding the penalty of constant GPU→CPU security checks. ### ✅ Export Guards (bufferToBlob, captureFrame) Added early-return guards to functions that call `toBlob`/`toDataURL`: - **`bufferToBlob()`** in bios.mjs - Returns `null` with warning in sandbox - **`captureFrame()`** in frame-capture.mjs - Returns `null` in sandbox --- ## Recommendations ### For objkt.com / NFT Platforms 1. **Add `allow-same-origin`** to sandbox attribute for art pieces 2. Or provide a performance toggle (like objkt's "Advanced Mode") ### For KidLisp Bundles 1. ✅ **Already done**: Disabled `acPACK_MODE` (screenshot features) 2. ✅ **Already done**: Disabled console auto-snaps 3. ✅ **Implemented**: Detect sandboxed context and log warning 4. **Consider**: Use `OffscreenCanvas` for heavy operations (when supported) ### For Aesthetic Computer Runtime 1. ✅ **Implemented**: Detect opaque origin early 2. ✅ **Implemented**: Skip impossible operations (`toBlob`, `toDataURL`) 3. ✅ **Implemented**: Add `willReadFrequently` hint to canvas contexts 4. **Consider**: Add FPS counter warning in sandbox mode --- ## Files Changed | File | Changes | |------|---------| | [bios.mjs](../system/public/aesthetic.computer/bios.mjs) | Added `isOpaqueOrigin` detection, `willReadFrequently` hints, `bufferToBlob` guard | | [frame-capture.mjs](../system/public/aesthetic.computer/lib/frame-capture.mjs) | Added `isOpaqueOrigin` guard to `captureFrame()` | --- ## References - [WHATWG HTML Spec - Canvas Security](https://html.spec.whatwg.org/multipage/canvas.html#security-with-canvas-elements) - [MDN - getImageData() Security](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/getImageData) - [MDN - iframe sandbox attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#sandbox) - [MDN - Same-origin policy](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy) --- *Report generated: January 27, 2026* *Context: FF1 display device performance investigation for objkt.com tokens* *Updated: Added implementation details for sandbox detection and canvas optimizations*