Bug 149708 - Web Inspector: Clip string previews
Summary: Web Inspector: Clip string previews
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Local Build
Hardware: All All
: P2 Normal
Assignee: Nikita Vasilyev
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-10-01 08:53 PDT by Nikita Vasilyev
Modified: 2015-10-01 12:54 PDT (History)
9 users (show)

See Also:


Attachments
[Image] Bug (440.01 KB, image/png)
2015-10-01 08:53 PDT, Nikita Vasilyev
no flags Details
[HTML] Reduction (2.63 KB, text/html)
2015-10-01 09:07 PDT, Nikita Vasilyev
no flags Details
Patch (2.79 KB, patch)
2015-10-01 09:19 PDT, Nikita Vasilyev
no flags Details | Formatted Diff | Diff
[Animated GIF] With the patch applied (251.20 KB, image/gif)
2015-10-01 09:26 PDT, Nikita Vasilyev
no flags Details
[Animated GIF] With the patch applied (stack traces) (76.06 KB, image/gif)
2015-10-01 09:35 PDT, Nikita Vasilyev
no flags Details
Patch (3.73 KB, patch)
2015-10-01 10:46 PDT, Nikita Vasilyev
joepeck: review+
Details | Formatted Diff | Diff
Patch (3.75 KB, patch)
2015-10-01 12:01 PDT, Nikita Vasilyev
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nikita Vasilyev 2015-10-01 08:53:49 PDT
Created attachment 262256 [details]
[Image] Bug

Currently, console.log("A 2MB string", aLongLongString) shows the whole string in the preview. There is no limit on how long a string can be.

Hovering over aLongLongString in the debugger will show the whole string on a single line.

We should clip long strings in the previews.
Comment 1 Radar WebKit Bug Importer 2015-10-01 08:54:05 PDT
<rdar://problem/22933240>
Comment 2 Nikita Vasilyev 2015-10-01 09:07:23 PDT
Created attachment 262257 [details]
[HTML] Reduction
Comment 3 Nikita Vasilyev 2015-10-01 09:19:00 PDT
Created attachment 262259 [details]
Patch
Comment 4 Nikita Vasilyev 2015-10-01 09:26:22 PDT
Created attachment 262262 [details]
[Animated GIF] With the patch applied
Comment 5 Nikita Vasilyev 2015-10-01 09:35:02 PDT
Created attachment 262263 [details]
[Animated GIF] With the patch applied (stack traces)

The patch makes console messages with clipped strings expandable, so it also mitigates "Web Inspector: Can't click on a stack trace link when it's in a console message preview" https://bugs.webkit.org/show_bug.cgi?id=149638.
Comment 6 Devin Rousso 2015-10-01 09:44:03 PDT
This makes sense to me, but I think that the clipping could be a bit smarter.  Is there a reason that you didn't have it attempt to find a \s somewhere immediately before the 140 character limit to provide "nicer" splitting?  If there is a stream of characters with no breaks (like a URL) then this makes sense, but for words I think it should try splitting more nicely.  Otherwise, super awesome.
Comment 7 Nikita Vasilyev 2015-10-01 10:46:23 PDT
Created attachment 262268 [details]
Patch
Comment 8 Nikita Vasilyev 2015-10-01 10:56:52 PDT
Comment on attachment 262268 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=262268&action=review

> Source/WebInspectorUI/UserInterface/Base/Utilities.js:481
> +        "use strict";

If I don't use strict, "abc".truncate(3) would create a new object: https://cloudup.com/cRM82I1lE8d
Using strict makes it no-op.

> Source/WebInspectorUI/UserInterface/Base/Utilities.js:488
> +        if (matched && matched[0].length < Math.floor(maxLength / 2))

"1 234".truncate(5) should return "1 23…" and not "1…", so I used this Math.floor(maxLength / 2)
Comment 9 Joseph Pecoraro 2015-10-01 11:34:30 PDT
Comment on attachment 262268 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=262268&action=review

Looks fine to me. But some questions. r=me

>> Source/WebInspectorUI/UserInterface/Base/Utilities.js:481
>> +        "use strict";
> 
> If I don't use strict, "abc".truncate(3) would create a new object: https://cloudup.com/cRM82I1lE8d
> Using strict makes it no-op.

Wow. Why is that?

> Source/WebInspectorUI/UserInterface/Base/Utilities.js:487
> +        let matched = clipped.match(/\s[^\s]*$/);

I think it would be clearer to do something like:

let indexOfLastWhitespace = clipped.search(/\s\S*$/);
if (indexOfLastWhitespace > Math.floor(maxLength / 2))
    clipped = clipped.slice(0, indexOfLastWhitespace - 1);

For a while I didn't understand what you were doing here.
Comment 10 Nikita Vasilyev 2015-10-01 11:57:33 PDT
Comment on attachment 262268 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=262268&action=review

>>> Source/WebInspectorUI/UserInterface/Base/Utilities.js:481
>>> +        "use strict";
>> 
>> If I don't use strict, "abc".truncate(3) would create a new object: https://cloudup.com/cRM82I1lE8d
>> Using strict makes it no-op.
> 
> Wow. Why is that?

In non-strict mode "this" is always an object. Prototype methods on primitives (numbers, strings, boolean) force to create an object on every call. Strict mode allows "this" to be a primitive.

>> Source/WebInspectorUI/UserInterface/Base/Utilities.js:487
>> +        let matched = clipped.match(/\s[^\s]*$/);
> 
> I think it would be clearer to do something like:
> 
> let indexOfLastWhitespace = clipped.search(/\s\S*$/);
> if (indexOfLastWhitespace > Math.floor(maxLength / 2))
>     clipped = clipped.slice(0, indexOfLastWhitespace - 1);
> 
> For a while I didn't understand what you were doing here.

Completely forgot about the search method, thanks!
Comment 11 Nikita Vasilyev 2015-10-01 12:01:06 PDT
Created attachment 262272 [details]
Patch
Comment 12 WebKit Commit Bot 2015-10-01 12:54:42 PDT
Comment on attachment 262272 [details]
Patch

Clearing flags on attachment: 262272

Committed r190426: <http://trac.webkit.org/changeset/190426>
Comment 13 WebKit Commit Bot 2015-10-01 12:54:47 PDT
All reviewed patches have been landed.  Closing bug.