can I prevent Chrome from truncating strings in the dev console?

I recently discovered that the Chrome dev tools has a copy function which copies to clipboard - without truncation! Handily it also serializes objects to JSON and DOM elements to HTML, straight to the clipboard.

copy(someLongString); // no truncation!
copy({ foo : true }); // JSON
copy(someDOMElement); // HTML

Since I was trying to copy a long string to clipboard for analysis elsewhere, this served my needs perfectly

Edit in 2021: Seems Chrome now adds a handy button in console for copying long strings:

screenshot of chrome's new "Copy" button in console

Here's some code to test the feature:

var str = ""; 

// generate 30kb hex string
for(var i = 0; i < (1024 * 30); i++) { 
  str += (i % 16).toString(16) 
}; 

// just so we know it copied the whole thing
str += "END"; 

console.dir(longstringhere) works.

copy didn't work for me either, it was saying it's undefined.


This behavior still exists in Chrome Version 37.0.2062.103.

You can get around this while debugging by using: document.write('My Really Long Debug Text');


I use the following:

var text = 'a really long string';
window.prompt("Copy to clipboard", text);

then copy the text from the edit field.


Upgrade Chrome to version 32 which no longer does this, as shown by this picture:

enter image description here