From b80cca5731c250e1b2f015eb1c2a83231666b658 Mon Sep 17 00:00:00 2001 From: arzumify Date: Wed, 5 Feb 2025 17:21:55 +0000 Subject: [PATCH] Patched apple phones not being able to read from jsStreams for some unknown reason (3) --- main.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index f69c43d..95ab043 100644 --- a/main.go +++ b/main.go @@ -190,22 +190,22 @@ func (t *Transport) RoundTrip(req *Request) (resp *Response, err error) { } // Safari doesn't support readable streams - if !js.Global().Get("ApplePaySession").IsUndefined() { + println("Trying duck test") + if js.Global().Get("ApplePaySession").IsUndefined() { + println("Not an apple") resp.Body = jsStreams.NewReadableStream(args[0].Get("body")) } else { // Read in the body with .arrayBuffer() - promise := args[0].Call("bytes") - var waitGroup sync.WaitGroup + promise := args[0].Call("arrayBuffer") waitGroup.Add(1) promise.Call("then", js.FuncOf(func(this js.Value, args []js.Value) interface{} { - b := make([]byte, args[0].Get("length").Int()) - js.CopyBytesToGo(b, args[0]) + uint8Array := js.Global().Get("Uint8Array").New(args[0]) + b := make([]byte, uint8Array.Get("length").Int()) + js.CopyBytesToGo(b, uint8Array) resp.Body = io.NopCloser(bytes.NewReader(b)) waitGroup.Done() return nil })) - - waitGroup.Wait() } // Standard-library compatibility fields @@ -675,7 +675,7 @@ func Get(url string) (response *Response, err error) { return } // Disable if not https, we don't detect chromium, or we are on safari - if !strings.HasPrefix(url, "https://") || !js.Global().Get("chrome").IsUndefined() || !js.Global().Get("ApplePaySession").IsUndefined() { + if !strings.HasPrefix(url, "https://") || !js.Global().Get("chrome").IsUndefined() || js.Global().Get("ApplePaySession").IsUndefined() { request.DisableStreamedClient = true } response, err = Fetch.Do(request) @@ -692,7 +692,7 @@ func Post(url string, contentType string, body io.Reader) (response *Response, e return } // Disable if not https, we don't detect chromium, or we are on safari - if !strings.HasPrefix(url, "https://") || !js.Global().Get("chrome").IsUndefined() || !js.Global().Get("ApplePaySession").IsUndefined() { + if !strings.HasPrefix(url, "https://") || !js.Global().Get("chrome").IsUndefined() || js.Global().Get("ApplePaySession").IsUndefined() { request.DisableStreamedClient = true } request.Header.Add("Content-Type", contentType) @@ -712,7 +712,7 @@ func PostForm(url string, data url.Values) (response *Response, err error) { } request.Header.Add("Content-Type", "application/x-www-form-urlencoded") // Disable if not https, we don't detect chromium, or we are on safari - if !strings.HasPrefix(url, "https://") || !js.Global().Get("chrome").IsUndefined() || !js.Global().Get("ApplePaySession").IsUndefined() { + if !strings.HasPrefix(url, "https://") || !js.Global().Get("chrome").IsUndefined() || js.Global().Get("ApplePaySession").IsUndefined() { request.DisableStreamedClient = true } response, err = Fetch.Do(request)