72
> ary = new Array('test msg kinda long but gets the point across and such and it shows ellipsises after a certain point in my test. test msg kinda long but gets the point across and such and it shows ellipsises after a certain point in my test. test msg kinda long but gets the point across and such and it shows ellipsises after a certain point in my test. test msg kinda long but gets the point across and such and it shows ellipsises after a certain point in my test. test msg kinda long but gets the point across and such and it shows ellipsises after a certain point in my test.');
> JSON.stringify(ary)
"["test msg kinda long but gets the point across and such and it shows ellipsises... (length: 116)"

I really want the full object, but Chrome wants to trim the result at about 80 characters. I don't see anything in the console settings that would change this.

2
  • I solve this by clicking 'View Page Source'
    – Mark Khor
    Jan 8 at 11:20
  • That doesn't work for JavaScript objects
    – jcollum
    Jan 11 at 20:29

9 Answers 9

69

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"; 
11
  • 5
    that's slick; doesn't really answer the question though, should be a comment instead
    – jcollum
    Sep 24, 2014 at 18:12
  • 2
    +1 this is so useful. Granted it doesn't technically answer the question but it solves the problem causing the question to be asked - how to get the full, untruncated text from the console. Just paste it into a text editor and you're sorted.
    – theyetiman
    May 19, 2015 at 10:58
  • I got in Chrome: Uncaught ReferenceError: copy is not defined
    – arod
    Jan 8, 2016 at 16:52
  • 4
    @arod it's only available in the console, not gobally Jan 12, 2016 at 16:19
  • 2
    This works in Firefox too.
    – Björn
    May 3, 2018 at 7:23
30

console.dir(longstringhere) works.

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

7
  • 1
    Same here. 'console.copy' didn't work but 'console.dir' worked. You saved my day.
    – Betty
    Jul 8, 2016 at 3:53
  • 4
    copy function does not output anything (hence undefined is expected), instead it copies argument to your system buffer, just paste it (ctrl-v) into any editor
    – nazikus
    Aug 12, 2016 at 17:04
  • 1
    not working.... Dec 26, 2016 at 14:23
  • 2
    You must copy from the console e.g. place a breakpoint where the value is, open console, type copy(yourVariable). Also, it's just copy not console.copy Jan 26, 2017 at 13:11
  • 1
    Every function in JS returns undefined if not specified. So it actually works.
    – atilkan
    Jun 11, 2018 at 22:36
6

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');

3
  • 37.0.2062.120 m on Windows 7: no ellipses.
    – jcollum
    Sep 19, 2014 at 19:30
  • Not working anymore..
    – Totty.js
    Jun 23, 2017 at 15:21
  • Nov 2021: Chrome is now version 95. Holy crap they increment their major version a lot.
    – jcollum
    Nov 4, 2021 at 17:20
4

I use the following:

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

then copy the text from the edit field.

1
  • This is also truncated Oct 12, 2018 at 7:55
3

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

enter image description here

9
  • 2
    chrome canary v36+... it still does that. ...but now does not show the length. e.g. long string...ends here.
    – gcb
    May 1, 2014 at 16:35
  • You're in a version of chrome that hasn't been released yet. It's not happening in v33 on Ubuntu: imgur.com/RPCgR6f -- did you downvote me because my solution didn't fix your problem even though you're in a pre-release version?!
    – jcollum
    May 1, 2014 at 16:44
  • 1
    "solve the problem. running an old browser version is not possible " --- it's not an old browser version! I'm up to date and at v33 in ubuntu. My windows box is up to date and it's v34. I don't know where you're getting v36 from. "it does not happen on v33" -- and it doesn't, which the screenshot (from v33) proves.
    – jcollum
    May 1, 2014 at 21:27
  • 1
    the key takeaway is that this bug/behaviour was inserted back after 33 or 34.
    – gcb
    May 2, 2014 at 18:57
  • 1
    That's nice. You should submit a bug report. Since the current released version of Chrome doesn't have it, you shouldn't downvote me for saying updating to the newest released version of Chrome fixes it. And that holds true for V34 on Win7 and V33 on Ubuntu.
    – jcollum
    May 2, 2014 at 19:55
3

The length of the string that is rendered to the console is limited programatically inside inspector.js. It's set to 150 characters by default. There's no CSS you can apply because it is being rendered to the console as HTML. The text has already been truncated.

You can change it but it's going to take a little bit of work:

Necessary and Helpful Tools:

• ack (brew install ack) or ag. (for searching huge text files really fast).

• paktools for python. For unpacking the chrome resources to be able to edit them. https://github.com/Magister/pak-tools.

• text editor of choice.

  1. cd or navigate into whatever version of Chrome you have. I am using Chromium as an example but the path is the same on other versions:

    cd "/Applications/Chromium.app/Contents/Versions/YOURVERSION/Chromium Framework.framework/Resources/"
    
  2. Clone or download the paktools. This will allow your to unpack the chrome resources, edit them and then repack them. I placed mine in my ~./bin but you can put them anywhere. Examples will mirror my path:

  3. Now in the Chrome/.../Chrome Framework.framework/Resoures folder execute: python2 ~/.bin/unpack.py resources.pak and cd ./resouces

  4. You're going to have to find where it is. The files change all the time and so it's never the same. $ ag "static linkify" That took me to 28542. I modified the function to default to 2000 chars, and also updated the css so I could scroll horizontally in the console.

  5. now cd back out of the resouces folder you unpacked and into it's parent. Execute: python2 ~/.bin/pack.py resources and voila. Restart Chrome and your devtools are now custom.

WARNING: 6. The devtools team pushes out updates the framework's versions without you knowing. And you'll lose all your mods if they do. I block it by executing /Users/Op/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/Resources/ksinstall --uninstall and killing all the keystone deamons etc.

Works like a charm.

enter image description here

2

In Chrome 58 (maybe earlier) you can use the Store as Global Variable menu option on the contextual menu of any value in the console, nested at any level. It assigns the selected value to a variable with a unique name, which is immediately logged to the console.

Just tried it on a 400KB value!

Source: https://stackoverflow.com/a/41726364/250838

1
  • Good solution +1
    – jcollum
    Nov 18, 2020 at 22:54
1

For strings inside of a <script> tag, none of the existing answers work and the output remains truncated. However you can find your full string in the Sources tab - just switch to the tab and CTRL + F search for part of your string.

0

After getting fed up with Chrome truncating everything I finally just threw the json I needed into a dom element. It is definately not the most elegant solution, but it works when you really need the output.

const div = document.createElement('div')
div.innerText = JSON.stringify(data)
document.body.appendChild(div)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .