RESOLVED FIXED Bug 165230
Web Inspector: Some resources fetched via Fetch API do not have data
https://bugs.webkit.org/show_bug.cgi?id=165230
Summary Web Inspector: Some resources fetched via Fetch API do not have data
Joseph Pecoraro
Reported 2016-11-30 16:36:12 PST
Summary: Some resources fetched via Fetch API do not have data Steps to Reproduce: 1. fetch("data.json") 2. Select "data.json" in Resources tab => No data Notes: - We have existing InspectorInstrumentation methods to stash XHR data: InspectorInstrumentation::didReceiveXHRResponse InspectorInstrumentation::didFinishXHRLoading - We likely need to do the same for Fetch - How does EventSource fit into this as well?
Attachments
[PATCH] Proposed Fix (48.97 KB, patch)
2016-12-06 15:48 PST, Joseph Pecoraro
joepeck: review-
[PATCH] Proposed Fix (57.36 KB, patch)
2016-12-07 20:51 PST, Joseph Pecoraro
achristensen: review+
Radar WebKit Bug Importer
Comment 1 2016-11-30 16:37:56 PST
youenn fablet
Comment 2 2016-12-01 03:49:27 PST
> Notes: > - We have existing InspectorInstrumentation methods to stash XHR data: > InspectorInstrumentation::didReceiveXHRResponse > InspectorInstrumentation::didFinishXHRLoading > - We likely need to do the same for Fetch It would be great if we could remove those XHR specific APIs and use generic APIs at DocumentThreadableLoader level. Inspector should be able to do specific processing (XHR, fetch) if needed based on the initiator. > - How does EventSource fit into this as well? EventSource behaves a bit differently since data is long living. That might require being able to show received data before the response is finished. Is it already supported?
Joseph Pecoraro
Comment 3 2016-12-06 15:48:19 PST
Created attachment 296338 [details] [PATCH] Proposed Fix
Joseph Pecoraro
Comment 4 2016-12-06 15:48:32 PST
*** Bug 165228 has been marked as a duplicate of this bug. ***
WebKit Commit Bot
Comment 5 2016-12-06 15:49:34 PST
Attachment 296338 [details] did not pass style-queue: ERROR: Source/WebCore/platform/network/ResourceRequestBase.h:163: enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums. [readability/enum_casing] [4] Total errors found: 1 in 37 files If any of these errors are false positives, please file a bug against check-webkit-style.
Joseph Pecoraro
Comment 6 2016-12-06 15:50:45 PST
> EventSource behaves a bit differently since data is long living. > That might require being able to show received data before the response is > finished. > Is it already supported? Not supported yet. We should handle this when we start better handling streaming data (Web Sockets, Fetch, Media, Event Source). Bug 164890 tracks that.
youenn fablet
Comment 7 2016-12-06 23:35:39 PST
I know the current patch is following xhr/inspector current pattern. I would prefer though that we hook response inspector callback in DocumentThreadableLoader::didReceiveResponse if that is not too complex. This could be limited to fetch requests using requester information to limit risk of breaking things.
Joseph Pecoraro
Comment 8 2016-12-07 17:14:47 PST
(In reply to comment #7) > I know the current patch is following xhr/inspector current pattern. > > I would prefer though that we hook response inspector callback in > DocumentThreadableLoader::didReceiveResponse if that is not too complex. Yes, I should be able to do this. Looking at it now. But I still think we would want the new Requester Type on ResourceResponseBase so that we can know at willSendRequest time the type. As I learn more about how networking works we may be able to clean this up further.
Joseph Pecoraro
Comment 9 2016-12-07 20:51:33 PST
Created attachment 296477 [details] [PATCH] Proposed Fix I think this should better match your expectations Youenn. Let me know if it doesn't.
WebKit Commit Bot
Comment 10 2016-12-07 20:53:59 PST
Attachment 296477 [details] did not pass style-queue: ERROR: Source/WebCore/platform/network/ResourceRequestBase.h:163: enum members should use InterCaps with an initial capital letter or initial 'k' for C-style enums. [readability/enum_casing] [4] Total errors found: 1 in 34 files If any of these errors are false positives, please file a bug against check-webkit-style.
Joseph Pecoraro
Comment 11 2016-12-07 20:54:10 PST
Comment on attachment 296477 [details] [PATCH] Proposed Fix View in context: https://bugs.webkit.org/attachment.cgi?id=296477&action=review > Source/WebCore/inspector/InspectorInstrumentation.h:-863 > - if (cookie.isValid()) > - didReceiveResourceResponseImpl(cookie, identifier, loader, response, resourceLoader); This check was unnecessary because it is done immediately inside didReceiveResourceResponseImpl which it calls unconditionally. Technically we can eliminate these functions but I'll do other cleanup later, I'm investigating something related.
Alex Christensen
Comment 12 2016-12-08 16:40:34 PST
Comment on attachment 296477 [details] [PATCH] Proposed Fix View in context: https://bugs.webkit.org/attachment.cgi?id=296477&action=review > Source/WebCore/inspector/InspectorNetworkAgent.cpp:459 > + if (initiator == cachedResourceRequestInitiators().fetch) > + m_resourcesData->setResourceType(IdentifiersFactory::requestId(identifier), InspectorPageAgent::FetchResource); > + else if (initiator == cachedResourceRequestInitiators().xmlhttprequest) Should we do anything if both of these are false? ASSERT_NOT_REACHED()? > Source/WebCore/inspector/InspectorPageAgent.cpp:326 > case CachedResource::MainResource: > return InspectorPageAgent::DocumentResource; > + case CachedResource::MediaResource: > + case CachedResource::RawResource: { > + switch (cachedResource.resourceRequest().requester()) { > + case ResourceRequest::Requester::Fetch: > + return InspectorPageAgent::FetchResource; > + case ResourceRequest::Requester::Main: > + return InspectorPageAgent::DocumentResource; > + default: > + return InspectorPageAgent::XHRResource; > + } > + } I don't understand why media resources should enter the switch statement that only returns fetch, document, or xhr. Do we consider media resources to be xhr resources? Can either of them be a main resource? We already have a case for main resources in the parent switch statement.
Joseph Pecoraro
Comment 13 2016-12-08 19:55:08 PST
Comment on attachment 296477 [details] [PATCH] Proposed Fix View in context: https://bugs.webkit.org/attachment.cgi?id=296477&action=review >> Source/WebCore/inspector/InspectorNetworkAgent.cpp:459 >> + else if (initiator == cachedResourceRequestInitiators().xmlhttprequest) > > Should we do anything if both of these are false? ASSERT_NOT_REACHED()? It is fine to not assert. We are only specializing ThreadableLoader loads for loads that have specific Inspector types (xhr, and fetch). We may have others in the future (such as event source). >> Source/WebCore/inspector/InspectorPageAgent.cpp:326 >> + } > > I don't understand why media resources should enter the switch statement that only returns fetch, document, or xhr. Do we consider media resources to be xhr resources? Can either of them be a main resource? We already have a case for main resources in the parent switch statement. The Media case is not changing here. Web Inspector still does not fully support media resources. Handling of CachedResource::Media was added by someone who did not understand Inspector code at a point where CachedResource::Media was split off of CachedResource::Raw so it was just made to copy CachedResource::Raw. Fixing Media resources is a separate issue.
Alex Christensen
Comment 14 2016-12-09 00:12:41 PST
Comment on attachment 296477 [details] [PATCH] Proposed Fix Ok, the rest of this code looks good to me.
youenn fablet
Comment 15 2016-12-09 00:24:20 PST
This looks great to me as well! Would you be able to add some tests with opaque or filtered responses? For instance, fetch no-cors and cross origin URL. And another with filtered response headers? We should expect inspector to show the whole data although the web app should not see it.
Joseph Pecoraro
Comment 16 2016-12-09 14:12:08 PST
(In reply to comment #15) > This looks great to me as well! > Would you be able to add some tests with opaque or filtered responses? > For instance, fetch no-cors and cross origin URL. And another with filtered > response headers? Gladly! I'll start writing a lot more tests over on bug 165683. Which I'll start on now.
Joseph Pecoraro
Comment 17 2016-12-09 14:13:44 PST
Note You need to log in before you can comment on or make changes to this bug.