How to copy watched javascript variable in Chrome? How to copy watched javascript variable in Chrome? google-chrome google-chrome

How to copy watched javascript variable in Chrome?


I'm adding a late answer after nearly 3 years because with the current Chrome Dev Tools, neither approach work if you have an Array or even just a nested Object property in that variable, following both answers you'll just end up copying a string with a lot of Array[size] or Object strings interleaved in the actual object value, completely useless for complex object hierarchies.

The suggested approaches are ok if you just need to manually navigate through the value but not if you need to copy it as requested in the question.

What i recommend instead, especially if you need to copy the watched value to use it as the content of a new variable, is to dump it to console after it has been stringified.

Show the Javascript console and type:

console.log(JSON.stringify(my_watched_var))

This way the complete structure will be displayed in pure Javascript, a fully reusable/copyable way.


Chrome DevTools' console command-line has a built-in "copy" function:

copy(my_variable)

If the value of my_variable is not a string, it will automatically be converted to JSON. The resulting string is left on the system clipboard for pasting.

Here's the reference doc.


Show the console, then type the expression to be displayed and press . You'll see whole value and you'll be able to select and copy it.

While the debugger is paused, this works even with expressions that involve local variables that are in scope at the current point of execution.