brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: copy() in the DevTools console puts a result on your clipboard

Devtools
~/tips/tip-devtools-console-copy

copy($$('a').map(a => a.href))

Copies the result of a console expression to the clipboard as text.

Selecting long console output with the mouse and copying it is clumsy. There is a function that skips the mouse entirely.

copy(object) is one of the Console utilities. It copies a string representation of whatever you give it to the clipboard. A typical use is grabbing every link on a page:

copy($$('a').map(a => a.href))

$$(selector) is the Console’s shortcut that returns an array of all elements matching a CSS selector. After map you have an array of URLs, copy() puts it on the clipboard, and you can paste it into an editor.

It pairs well with $_, which holds the result of the most recently evaluated expression. If you ran something and now want it in your notes, there is no need to run it again:

copy($_)

One limit: this is a Console-only helper, so it does nothing in a script on your page. And what lands on the clipboard is a string form of the object. Paste it somewhere and read it before you rely on it, because a complex object can look different from the tree the Console shows.

Further reading: Chrome DevTools: Console Utilities API reference

More Devtools tips Clear site data for one site from Chrome DevTools user.id === 42 $x(path [, startNode]) @media (prefers-color-scheme: dark) { queryObjects(Promise) All Devtools tips (22) All topics

Link