Bug 203617

Summary: "ReadableStream uploading is not supported" when fetch()ing a Request that has been logged to console
Product: WebKit Reporter: Jeffrey Posnick <webkit>
Component: Service WorkersAssignee: youenn fablet <youennf>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, bakkot, beidson, james.webkittracker, philip, tomac, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: Safari 13   
Hardware: All   
OS: All   
Attachments:
Description Flags
Screenshot of the failure sequence.
none
Patch
none
Patch none

Description Jeffrey Posnick 2019-10-30 10:40:25 PDT
Created attachment 382328 [details]
Screenshot of the failure sequence.

This came up at https://github.com/GoogleChrome/workbox/issues/1732, and was originally mentioned at https://stackoverflow.com/questions/49850705. While it has more to do with the Fetch API than Service Workers, I didn't see a dedicated Component for Fetch, so I chose Service Workers.

An attempt to call fetch(request) will lead to a "NotSupportedError: ReadableStream uploading is not supported" when request is a Request object that contains a body and has been previously logged to the JS console. This failure occurs whether the logging is implicit, by virtue of typing in an interactive command in the JS console (which logs the return value immediately after execution) or explicit from code, via console.log(request).

You can reproduce this issue by navigating to https://example.com in any recent version of Safari (I tested with Safari 13 on OS X 10.14.6), choosing "Show JavaScript console" from the Develop menu, and entering the following:

> res = await fetch(new Request('https://example.com', {method: 'POST', body: Math.random()}))
< undefined
[Info] Response {type: "basic", url: "https://example.com/", redirected: false, status: 200, ok: true, …}

> req = new Request('https://example.com', {method: 'POST', body: Math.random()})
< Request {method: "POST", url: "https://example.com/", headers: Headers, destination: "", referrer: "about:client", …}
> res = await fetch(req)
NotSupportedError: ReadableStream uploading is not supported

The first sequence succeeds, because the new Request is created inside of the fetch() call and is not logged to the JS console.

The second sequence fails, because the new Request is logged to the JS console automatically after creation, and then using it via fetch(req) triggers the exception.

Attached is a screenshot of this in action if that's easier to follow.

No other browsers demonstrate this issue. Logging a request to the JS console should change whether or not the request is eligible to be sent via fetch(). Presumably whatever ends up implicitly converting the Request body to a ReadableStream should be disabled when logging to the JS console.
Comment 1 Radar WebKit Bug Importer 2019-10-30 23:02:47 PDT
<rdar://problem/56772045>
Comment 2 Kevin Gibbons 2021-12-16 17:20:49 PST
Logging to the console isn't the problem, it's trying to access the `body` property at all. A simpler reproduction is


```
let req = new Request('/', { method: 'post', body: 'stuff' });
req.body; // this has effects! remove it and the line below will work
fetch(req); // this doesn't work
```
Comment 3 youenn fablet 2022-01-05 02:08:10 PST
Created attachment 448371 [details]
Patch
Comment 4 youenn fablet 2022-01-05 05:30:32 PST
Created attachment 448381 [details]
Patch
Comment 5 EWS 2022-01-06 01:31:04 PST
Committed r287675 (245772@main): <https://commits.webkit.org/245772@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 448381 [details].