Skip to content
UniKit

JavaScript playground

Actually run JavaScript inside a Blob Worker: console output and errors are sent straight back, the worker is killed after a 2-second timeout, and network APIs are stubbed out.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

JavaScript code

The code really runs in a browser Worker; all five console methods are captured. import / importScripts are unsupported and the page DOM is unreachable.

Execution output

Output is concatenated in execution order; the run time is measured inside the Worker.

Enter code and press "Run code"

Sandbox note: network APIs are replaced with throwing stubs, but this is best-effort isolation — do not run code you do not trust.

What this tool does

  • Sanity-check a snippet (array work, date formatting, regex, string building) without opening devtools
  • Paste AI-generated code and see its console output before deciding whether to keep it
  • Show how logs and errors look: thrown errors are captured as a single line without writing try/catch

Example

Input

const nums = [1, 2, 3];
console.log(nums.map(n => n * 2).join(","));

Output

[log] 2,4,6
Finished in 0.3 ms

console.log values are formatted and sent back; the elapsed time is measured inside the Worker, so the number differs on every run.

Frequently asked questions

Does the code really run?

Yes. The page creates a one-off Worker from a Blob, runs the code inside a sandbox with a rewritten console, and terminates the worker afterwards. Console output, values and thrown errors are posted back to the main thread, so what you see is a real execution, not a static preview.

How does the timeout work?

The default is 2000 ms and the field accepts 100–10000 ms. When it hits, the worker is terminated, already-posted output is kept and a timeout hint is appended. Infinite loops and huge loops take this path, so the page never freezes.

Can it reach the network?

No. Inside the sandbox fetch, XMLHttpRequest, WebSocket, EventSource, importScripts and navigator are replaced with throwing stubs, and the pure logic refuses code containing fetch( / XHR / WebSocket / importScripts / import() before it runs. Be aware that this is best-effort isolation, not a security sandbox — do not run code you do not trust.

Why does accessing document / window fail?

Because the code runs in a Worker, which has no DOM. That is exactly why it cannot accidentally modify the page; code that needs the DOM belongs in devtools or in your own page.

How are syntax errors reported?

Before running, the code is parsed with new Function, so syntax errors are reported locally as "syntax error + detail" without waiting for the worker. Runtime exceptions are shown as a single line starting with [error], including the error type and message.

Are there length limits on the code and the output?

Yes. A single run accepts at most 20,000 characters of code — longer input is rejected rather than partly executed. The text sent back is capped at 8,000 characters: the overflow is cut off and the output ends with the "输出已截断" (output truncated) marker, while everything printed before the cut is kept. Split longer snippets into several runs.

Keywords:Blob WorkerJavaScript playground

Related tools