Run JavaScript snippets and see the console output

Type or paste a JavaScript snippet, press Run, and its console output appears below, just as a browser console would print it. The code runs in an isolated sandbox with no network access.

Live demo · real result from this tool
Runs in an isolated sandbox with no network access. Press Ctrl+Enter to run.

Console output appears here.

Processed on your device — nothing is uploaded.

How to use the JS console simulator

  1. Type or paste code into the JavaScript box. A sample is there to start with.
  2. Press Run, or Ctrl+Enter. While a run is still going, the button reads Re-run and starts over.
  3. Read the output below. Each console call is one row: warnings are marked ▲ and errors ✖, and grouped rows are indented.
  4. The status line shows Finished in N ms, or why the run stopped. Press Stop to end a long run and Clear to empty the output.

What it does and when to use it

Use it to check what an expression returns, test an array method or a regex replace, or follow a tutorial example. It is quicker than opening developer tools, and the code cannot touch the page you are on.

It is not a full runtime. There is no DOM, no network and no npm packages, and the run is stopped after 5 seconds. To check syntax without running anything, use the JavaScript validator. To delete logs before you ship, use the console.log remover. To make a snippet readable first, run it through the JavaScript formatter.

How it works

When you press Run, the page creates a hidden frame with the sandbox="allow-scripts" setting and no same-origin permission, so the frame has an opaque origin. Inside it, a Web Worker runs your code with a replacement console object. Each call turns its arguments into a safe description of the values and posts it back to the page, which prints them the way browser consoles do: strings unquoted at the top level and quoted inside objects.

Besides log, info, warn, error and debug, it supports table, assert, count, time, group and clear, plus format strings such as %s and %d.

Worked examples

These rows come from the simulator’s own value printer.

Arrays and objects.

const users = [{ name: 'Asha', age: 31 }, { name: 'Ben', age: 27 }];
console.log('Users:', users.length);
console.table(users);
console.warn('Done');

prints Users: 2, then [ { name: 'Asha', age: 31 }, { name: 'Ben', age: 27 } ], then a warning row Done.

Format strings, counters and groups. console.log('%s scored %d%%', 'Asha', 92.7) prints Asha scored 92%, because %d keeps the whole number. Two console.count() calls print default: 1 and default: 2. Inside console.group('Totals'), console.log(new Map([['a', 1]]), new Set([1, 2])) prints an indented Map(1) { 'a' => 1 } Set(2) { 1, 2 }.

An error and a timer.

setTimeout(() => console.log('later'), 0);
console.log('now');
null.x;

shows now, then a red Uncaught TypeError row. later never appears, because the run had already finished.

Limits and tips

  • Output limits. Only the last 500 rows are kept. Arrays, maps and sets show their first 100 items, strings are cut at 10,000 characters, and objects nested more than 5 levels deep show [Object].
  • Top-level await is a syntax error, since the code runs as a script, not a module.

Frequently asked questions

Is it safe to run code I found online?
The code runs in a Web Worker inside a sandboxed frame with its own blank origin. It cannot read this page, your cookies or your storage, and network requests are blocked. Still, read unfamiliar code before running it.
Why don't my setTimeout or promise logs appear?
They do. The run waits until every setTimeout has fired and its promise callbacks have run before it reports Finished. A setInterval that is never cleared keeps the run going until the 5-second limit stops it.
Can I use document, window or alert?
No. The code runs in a worker, which has no page, so document and window are undefined and alert does not exist. Use the snippet for logic, data and string work, not for DOM code.
What happens with an infinite loop?
The page stays responsive because the loop runs in a separate worker. After 5 seconds the sandbox is stopped and the status line says so. You can also press Stop.
Does console.table draw a table?
Yes. It draws a text grid like Node does, with an (index) column, one column per property and a Values column for plain items. A second argument picks which columns to show.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close