diff --git a/main.go b/main.go index 8642fee..c1b917a 100644 --- a/main.go +++ b/main.go @@ -187,7 +187,24 @@ func (t *Transport) RoundTrip(req *Request) (resp *Response, err error) { resp.ContentLength = -1 } } - resp.Body = jsStreams.NewReadableStream(args[0].Get("body")) + + // Safari doesn't support readable streams + if strings.Contains(js.Global().Get("navigator").Get("userAgent").String(), "Safari") { + resp.Body = jsStreams.NewReadableStream(args[0].Get("body")) + } else { + // Read in the body with .arrayBuffer() + promise := args[0].Call("bytes") + var waitGroup sync.WaitGroup + waitGroup.Add(1) + promise.Call("then", js.FuncOf(func(this js.Value, args []js.Value) interface{} { + bytes := make([]byte, args[0].Get("length").Int()) + js.CopyBytesToGo(bytes, args[0]) + waitGroup.Done() + return nil + })) + + waitGroup.Wait() + } // Standard-library compatibility fields resp.Proto = "HTTP/1.1"