Webkit Develop Inspektor show long strings

2019-07-17 15:53发布

问题:

When i debug javascript in webkit browser(f.e. Safari), often i have some string variables and value of these variables are often very long, webkit make it shorter with "..." at the end, but i want to see all value of this variables, how can i do this?

回答1:

As far as I know all texts are truncated only when being listed as property of an object. If you're logging a text variable directly, it should show the whole text.

var foo = {bar:Array(1000).join('baz')};
console.log(foo); // this will truncate value of foo.bar
console.log(foo.bar); // this should show the whole text

If you still want to change the limit, here is my quick solution. It may not be the best way to do this, but if you can find a JS file responsible for Dev tools (for my Google Chrome installation the file is DevTools.js, for Safari 5 - InjectedScript.js), open it in a text editor, look for the function InjectedScript._describe. Inside this function you will find

if (obj.length > 100)
   return "\"" + obj.substring(0, 100) + "\u2026\"";

increase the limit from 100 to sth else or remove both lines.



回答2:

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