Documentation
Web Editor
Preview

Preview

CodeSandbox Projects Preview

When a running task opens a server on a port, that port will be attached to the task, turning it into a Preview type DevTool. Previews appear at the beginning of the list when you toggle the DevTools dropdown.

How do they work

WebSocket Override

We’ve patched WebSocket to ensure that always the right URL is accessed when opening a websocket. In the case that you try to access http://localhost:3000 using a websocket, we’ll rewrite it to https://3000-:id.preview.csb.app so the socket automatically connects to the right url.

This will often make hot module reloading work out of the box for frameworks like Vite.

Service Worker Proxy

If possible, we try to install a service worker in the preview that will proxy requests to localhost:3000 to the corresponding dev url. The service worker only proxies URLs that are going to localhost, or URLs that go to e.g. https://3000-:id.preview.csb.app:4000.