Skip to main content

JavaScript Playground

Run a JavaScript snippet in a sandboxed browser frame and see its console output, errors with line numbers, and run time.

For developers testing a quick idea without opening DevTools.

Last updatedHow we build & check our tools
Results will appear here once you enter your values.

How the sandbox works

Your code is placed in a generated HTML document and loaded into a hidden iframe through srcdoc. The iframe has sandbox="allow-scripts" and nothing else. MDN notes that omitting allow-same-origin gives the framed document an opaque origin, which is what stops it from touching this page's storage or DOM.

The document also carries a Content Security Policy with default-src 'none' and connect-src 'none', so the snippet cannot call out to a server or load images. The only channel back is postMessage, and the parent page accepts a message only if it comes from that frame, carries the per-run token, and has the expected shape.

  • Evaluation: the code runs through indirect eval, so top-level var and function declarations behave like global code.
  • Console: log, info, warn and error are replaced to forward their arguments to the output panel.
  • Errors: uncaught errors and unhandled rejections are reported with the line number from the stack when the browser provides one.

What it does not do

This is a scratchpad for short snippets, not a full runtime. There is no module loading, no network, no access to your page, and no output from code that runs after the synchronous part finishes. Debugger breakpoints, profiling and source maps are DevTools features and are not provided here.

  • Blocking code: a tight loop can hang the tab despite the timeout.
  • Untrusted code: the sandbox limits what a script can reach, but run only code you have read.
  • Browser differences: results come from your own browser's JavaScript engine, so behavior can differ from Node.js or another browser.

Sources

Sandboxing and message handling follow MDN Web Docs: the iframe element sandbox attribute, the srcdoc property, and Window.postMessage. Content Security Policy directives follow the W3C Content Security Policy specification.

Related tools: use the JSON Formatter to inspect object output, the Regex Tester to work on patterns, and the JavaScript Minifier to see how small your snippet gets.

Frequently Asked Questions

Common questions about the JavaScript Playground

The frame captures console.log, console.info, console.warn and console.error, plus uncaught errors and unhandled promise rejections. Strings print as written, objects and arrays print as JSON, and functions print as their source. Values that are not finite print as [non-finite number], and values that are not set print as a bracketed placeholder. Other console methods such as console.table are not captured, so use console.log instead.

From the same team

Turn your GPU into an OpenAI-compatible API endpoint

Wide Area AI routes your LLM API calls to your own hardware over a Cloudflare Tunnel — free local inference with edge caching and automatic cloud failover. Works with any OpenAI SDK.

Start routing — free

Sources & References

Web platform and protocol references

Authoritative definitions for web technologies, encodings, and data formats used by these developer tools.

Internet standards (RFCs)

Formal specifications for internet formats and protocols.