Skip to content
Run BunYour friendly Bun playground

Preview

When your code starts a server (Bun.serve, node:http, or export default { fetch }), the preview shows it. The request bar sends any request to it, and pages the server returns open in the preview.

Which server the preview shows when there are several

With several, it shows the program’s first; a program that serves nothing itself shows the first server one of its child processes starts (a package.json script that runs bun server.ts, a Bun.spawn), and the status bar lists those ports too. To see another of them, pick it in the status bar’s port list (in an embed, the ⋯ menu’s Preview port): the preview loads again from that server, and its WebSockets that name no port go there too, for as long as it runs. When it stops, the preview goes back to the default.

  • Request bar: send any method, path and body, with Params, Headers, Auth and Body sections and a Raw switch.

    The request panel under the bar has its toggle next to Send. It has Params, Headers, Auth and Body, and a Raw switch.

    Params and headers

    • Params lists the path’s query as rows and writes your edits back into the path.
    • Params and headers are rows you can turn off one by one; a param turned off leaves the path and keeps its place until you turn it on again.
    • Every header reaches the server, including ones a page’s fetch can’t set, such as Cookie, Origin and Referer.
    • A Cookie is joined with the cookies the app has set, and yours wins when a name is in both.
    • An HTML page you send headers to gets them on its first load, but not its scripts, fetches or links.

    Auth

    Auth sends a Bearer token, Basic credentials or an API key, the key as a header or a query parameter. What it adds shows as a read-only row under Headers or Params, and a header row with the same name wins over it.

    Body

    • A body is sent as JSON or text, written in the same editor as files (Format, or Shift+Alt+F in the body, indents a JSON body), or as a form, from rows.
    • A GET or HEAD request has no body; Body says so and offers to switch to POST.
    • A form is URL-encoded, or multipart, where a row can send a file from the project.

    Raw and copy

    • Raw shows the whole request as .http text in place of the section: the request line, a header per line (# turns one off), a blank line and the body. Edit it there and the other sections follow.
    • The copy menu copies the request as a curl command or a fetch call for http://localhost:3000, where the app runs when you start it locally with bun.

    Responses

    • A response from before the request last changed is dimmed, with a note to send it again.
    • Each preview tab keeps its own params, headers, auth and body.
    • HTML responses open in the page; anything else shows status, headers and the body: JSON formatted, and JSON, HTML, CSS, JavaScript, XML and Markdown highlighted.
    • A link or redirect in a page that leads to JSON or plain text shows it the same way, with its status but not its headers (the request isn’t sent again; press Send for them).
  • Tabs: several previews at once; Cmd-click or middle-click a link to open it in a new preview tab.

    Cmd-click (Ctrl-click off macOS) or middle-click a link in a page to open it in a new preview tab in the background; add Shift to switch to it.

  • Open in a new tab: the page gets its own browser tab, still served by the playground (keep the playground tab open).

  • Requests stay inside: fetch("/api/x"), links, forms and redirects from the preview page reach your server.

  • WebSockets: the preview page's WebSocket connects to your server, and so does the program's own new WebSocket.

    This works with Bun.serve upgrade, node:http upgrade and the ws package. localhost:<port> URLs pick the server on that port. The program’s own new WebSocket("ws://localhost:<port>") reaches its servers too.

  • Streaming: streamed responses and Server-Sent Events arrive as they’re sent.

  • Cookies are kept in the browser across restarts; list them with cookies in the console.

    The preview’s scripts read and set them with document.cookie and DevTools lists them (HttpOnly ones stay hidden from scripts and DevTools); see them with cookies.

  • HTML imports: import page from "./index.html" in Bun.serve routes is bundled with Bun's bundler.

    A browser-only project runs the way Bun runs it: Run (or bun ./index.html, or a "dev": "bun ./index.html" script) serves the page at / with its scripts and styles bundled, and bunfig.toml’s [serve.static] plugins apply.

  • The preview follows the playground’s light/dark mode.

Limits: the server isn’t reachable from outside the browser, there’s no HTTP caching (conditional requests are dropped), and only the preview page can open WebSockets to it.

For browser-only projects there is also an experimental way to skip the install and the worker: see Fast path for browser-only projects.

Was this page helpful?

Sends the rating and this page's address; nothing else unless you write it. Privacy

runbun is an independent project, not affiliated with or endorsed by Oven or Bun.