Skip to content
jshacks.dev
Debugging

Copy an object from the console with copy

Send any value from the DevTools console to your clipboard with copy, as formatted JSON, without selecting text by hand. Chrome and Firefox.

1 min read
Summarize in AI

Right-clicking and copying a large object from the console is clumsy and often gives a truncated string. The copy command puts the full value on the clipboard.

JavaScript
copy(JSON.stringify(window.__DATA__, null, 2));
Text
undefined

The command returns nothing, so the console prints undefined, and the clipboard now holds the formatted JSON. Paste it into an editor or an issue. It also takes strings directly: copy($0.outerHTML) copies the selected element's markup. See the Console Utilities reference.

copy converts objects with JSON.stringify-like logic when you pass one, but passing the result of JSON.stringify yourself, as above, lets you control the indentation and drop circular references first.

Like the other console commands, it only exists inside DevTools. A page script calling copy() fails with a ReferenceError, and in the page the standard way is navigator.clipboard.writeText, which needs a secure context and a user gesture.

Do not copy values that hold secrets, such as session tokens, into places that sync across devices.

Share

More snippets

Debugging

Group related logs with console.group

Indent related console output under a label with console.group and console.groupEnd, so interleaved logs from one request stay readable in Node.js 24.

1 min read
Debugging

Inspect an object with console.dir

Show nested objects beyond the default depth of two with console.dir and the depth option, instead of the [Object] placeholders console.log prints.

1 min read
Debugging

Debug a single Vitest test in VS Code

Run one Vitest file under the VS Code debugger with a launch configuration that passes the open file, so breakpoints in tests and source work. Vitest 3.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.