我可以防止 Chrome 在开发控制台中截断字符串吗?

jco*_*lum 63 google-chrome

> 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)"
Run Code Online (Sandbox Code Playgroud)

我真的想要完整的对象,但 Chrome 想要将结果修剪为大约 80 个字符。我在控制台设置中看不到任何会改变这一点的东西。

Wic*_*ams 64

我最近发现 Chrome 开发工具具有copy复制到剪贴板的功能 - 不会被截断!它还可以方便地将对象序列化为 JSON,将 DOM 元素序列化为 HTML,直接到剪贴板。

copy(someLongString); // no truncation!
copy({ foo : true }); // JSON
copy(someDOMElement); // HTML
Run Code Online (Sandbox Code Playgroud)

由于我试图将一个长字符串复制到剪贴板以在其他地方进行分析,这完全满足了我的需求

  • 那很光滑;不过并没有真正回答这个问题,应该是评论 (5认同)
  • @arod 它仅在控制台中可用,而不是全局可用 (4认同)
  • +1 这太有用了。当然,它在技术上并没有回答问题,但它解决了导致提出问题的问题 - 如何从控制台获取完整的、未截断的文本。只需将其粘贴到文本编辑器中即可进行排序。 (2认同)
  • 这也适用于 Firefox。 (2认同)

res*_*ing 22

console.dir(longstringhere) 作品。

copy也没有为我工作,它说的是undefined

  • `copy` 函数不输出任何内容(因此需要 `undefined`),而是将参数复制到系统缓冲区,只需将它(`ctrl-v`)粘贴到任何编辑器中 (4认同)
  • 您必须从控制台复制,例如在值所在的位置放置一个断点,打开控制台,输入“copy(yourVariable)”。此外,它只是`copy`而不是`console.copy` (2认同)

小智 5

此行为在 Chrome 版本 37.0.2062.103 中仍然存在。

您可以在调试时使用以下方法解决此问题: document.write('My Real Long Debug Text');