Bug 161422 - Web Inspector: XHR with text but responseType = "blob" shows blank content
Summary: Web Inspector: XHR with text but responseType = "blob" shows blank content
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Joseph Pecoraro
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2016-08-30 20:56 PDT by Joseph Pecoraro
Modified: 2016-08-31 15:18 PDT (History)
6 users (show)

See Also:


Attachments
[PATCH] Proposed Fix (14.34 KB, patch)
2016-08-30 21:03 PDT, Joseph Pecoraro
bburg: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2016-08-30 20:56:03 PDT
Summary:
XHR with text but responseType = "blob" shows blank content

Test:
<script>
let xhr = new XMLHttpRequest;
xhr.open("GET", "data.json", true);
xhr.responseType = "blob";
xhr.send();
</script>

Steps to Reproduce:
1. Inspect test
2. Reload
3. Select data.json resource
  => Content is blank, expected json content

Notes:
- XMLHttpRequest::didFinishLoad sets the content for the inspector, but it can set blank content if the XHR was loading binary data
Comment 1 Joseph Pecoraro 2016-08-30 20:56:14 PDT
<rdar://problem/28066869>
Comment 2 Joseph Pecoraro 2016-08-30 21:03:21 PDT
Created attachment 287478 [details]
[PATCH] Proposed Fix

We should really clean up our XHR <-> Inspector code. We may want to start sharing some of it with Fetch.
Comment 3 Brian Burg 2016-08-31 12:32:15 PDT
Comment on attachment 287478 [details]
[PATCH] Proposed Fix

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

r=me

So the bug is that we try to send gibberish decoded text instead of letting the inspector autodetect it or what? The changelog didn't really explain why this fix makes the frontend do anything different.

> LayoutTests/inspector/network/xhr-json-blob-has-content.html:33
> +                resource.singleFireEventListener(WebInspector.Resource.Event.LoadingDidFinish, (event) => {

The nesting here is getting excessive for my taste. I filed https://bugs.webkit.org/show_bug.cgi?id=161451 which could help.

> LayoutTests/inspector/network/xhr-json-blob-has-content.html:37
> +                        resolve();

I think it would be cleaner to remove this resolve(), then have

.then(resolve, reject)

or

.then(resolve).catch(reject)

at the end

> LayoutTests/inspector/network/xhr-json-blob-has-content.html:57
> +                        resolve();
> +                    }, reject);

Ditto
Comment 4 Joseph Pecoraro 2016-08-31 13:08:12 PDT
(In reply to comment #3)
> Comment on attachment 287478 [details]
> [PATCH] Proposed Fix
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=287478&action=review
> 
> r=me
> 
> So the bug is that we try to send gibberish decoded text instead of letting
> the inspector autodetect it or what? The changelog didn't really explain why
> this fix makes the frontend do anything different.

Somehow this got lost in my ChangeLog. Previously we were overwriting the content with an empty string. Now we don't.
Comment 5 Joseph Pecoraro 2016-08-31 15:18:34 PDT
<https://trac.webkit.org/changeset/205268>