@seanhogg/builderforce-webcontainers
v2026.10.12
Published
BuilderForce WebContainers — browser runtime. Boots an in-browser dev server for a project held in memory and serves it to an iframe through a service worker. Open source, no COOP/COEP, no session caps.
Maintainers
Readme
@seanhogg/builderforce-webcontainers
The browser runtime of BuilderForce WebContainers: boot an in-browser dev server and preview the project in an iframe. No COOP/COEP headers, no session caps, MIT licensed.
- Serve
dist/sw.jsfrom your site, ideally at/__bfwc/sw.jsso the worker's scope stays off the rest of your app. You can resolve its path withimport.meta.resolve('@seanhogg/builderforce-webcontainers/sw.js'), or copy it in your build. - Start and write the files:
import { startPreviewRuntime } from '@seanhogg/builderforce-webcontainers';
const runtime = await startPreviewRuntime({ serviceWorkerUrl: '/__bfwc/sw.js', id: projectId });
runtime.writeTree(files);
if (runtime.profile().supported) iframe.src = runtime.url;
else showFallback(runtime.profile().reason);To run untrusted code (AI-written, arbitrary packages), isolate the preview on its
own origin with startPreviewRuntime({ relayUrl }). That origin serves
relay.html, sw.js and process-worker.js (strings in @seanhogg/builderforce-webcontainers/assets)
with Content-Security-Policy: frame-ancestors limited to your app. See the
root README.
runtime.build({ base }) returns a deployable static site ({ files: [{ path, data }] }),
and createChecker() from @seanhogg/builderforce-webcontainers/check type-checks
the project in a Web Worker. .vue and .svelte files need no setup. See the
root README.
The package re-exports everything from
@seanhogg/builderforce-webcontainers-core.
