chatboxai/chatbox · error · Error
Preview not available
Error message
Preview not available
What it means
Thrown by readSandboxHtml (src/renderer/modals/ArtifactPreview.tsx:39) when the current platform has not implemented the optional platform.sandboxReadFileBase64 capability. The function is called from onPublish when publishing a sandboxed HTML artifact that has no inline htmlCode. Because sandbox reading is an optional platform interface method (see platform/interfaces.ts), platforms/shells that omit it cannot publish sandbox-only artifacts and hit this guard before any I/O.
Source
Thrown at src/renderer/modals/ArtifactPreview.tsx:39
import * as toastActions from '@/stores/toastActions'
export interface ArtifactPreviewProps {
htmlCode: string
previewUrl?: string
sandboxPath?: string
uniqueId?: string
sessionId?: string
}
function decodeBase64Utf8(base64: string): string {
const binary = atob(base64)
const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0))
return new TextDecoder().decode(bytes)
}
async function readSandboxHtml(sandboxPath: string): Promise<string> {
if (!platform.sandboxReadFileBase64) {
throw new Error('Preview not available')
}
const res = await platform.sandboxReadFileBase64({ filePath: sandboxPath })
if (!res.success || !res.base64) {
throw new Error(res.error || 'Preview not available')
}
return inlineSandboxHtmlAssets(decodeBase64Utf8(res.base64), sandboxPath, (assetPath) => {
if (!platform.sandboxReadFileBase64) {
return Promise.resolve({ success: false })
}
return platform.sandboxReadFileBase64({ filePath: assetPath })
})
}
const ArtifactPreview = NiceModal.create((props: ArtifactPreviewProps) => {
const { htmlCode, previewUrl, sandboxPath, uniqueId, sessionId } = props
const modal = useModal()
const { t } = useTranslation()
const [reloadSign, setReloadSign] = useState(0)View on GitHub (pinned to 81571269ad)
Solutions
- Disable or hide the Publish action on platforms without platform.sandboxReadFileBase64 (guard canPublish on the capability, not just on sandboxPath).
- Ensure the artifact carries inline htmlCode so publish does not depend on reading the sandbox.
- If you maintain a platform adapter, implement sandboxReadFileBase64 to read files from the sandbox and return { success, base64 }.
- Catch the error and show a clear 'publish not supported on this device' message rather than a generic failure.
Example fix
// before const canPublish = htmlCode.trim().length > 0 || !!sandboxPath // after (only offer sandbox-backed publish where the capability exists) const canPublish = htmlCode.trim().length > 0 || (!!sandboxPath && !!platform.sandboxReadFileBase64)
Defensive patterns
Strategy: validation
Validate before calling
// Gate publish on the capability, not just on having a sandbox path const canPublish = htmlCode.trim().length > 0 || (!!sandboxPath && !!platform.sandboxReadFileBase64)
Type guard
// Narrow the optional platform capability before calling
function canReadSandbox(
p: { sandboxReadFileBase64?: (...a: any[]) => any }
): p is { sandboxReadFileBase64: (params: { filePath: string }) => Promise<{ success: boolean; base64?: string; error?: string }> } {
return typeof p.sandboxReadFileBase64 === 'function'
} Try / catch
// onPublish already catches; keep the capability guard to avoid offering publish
try {
const html = htmlCode.trim() ? htmlCode : await readSandboxHtml(sandboxPath || '')
} catch (e) {
toastActions.add((e as Error)?.message || t('Publish failed'))
} Prevention
- Feature-detect platform.sandboxReadFileBase64 before showing the Publish button for sandbox-only artifacts.
- Prefer inline htmlCode for artifacts that must be publishable across all platforms.
- Implement the capability in any new platform adapter that ships the renderer.
- Do not assume desktop behavior on mobile/embedded shells.
When it happens
Trigger: ArtifactPreview.onPublish is invoked with an artifact whose htmlCode is empty but sandboxPath is set (canPublish true via sandboxPath), so readSandboxHtml(sandboxPath) runs. On a platform where platform.sandboxReadFileBase64 is undefined, the very first check throws 'Preview not available'. The publish then fails and the catch at line 83 shows a toast.
Common situations: Running the app on a platform variant that did not wire up sandbox file access (some mobile/embedded shells); a new target platform that reuses the renderer but not the desktop platform implementation; opening a shared/synced artifact whose source is only in the sandbox on a platform without sandbox support.
Related errors
- Offset ${startLine} is beyond end of file (${totalLines} lin
- Not found
- Failed to start preview server
- OAuth IPC is only available on desktop
- Command safety assessment requires system message support
AI-assisted analysis of chatboxai/chatbox@81571269ad (2026-08-12).
Data as JSON: /api/errors/e2fe9631a1bf5bf6.
Report an issue: GitHub.