From 42d2eb3c3c04e087b88df7252cd2c323b00a3f95 Mon Sep 17 00:00:00 2001 From: Chace Daniels Date: Thu, 6 Apr 2023 11:46:51 -0700 Subject: [PATCH] fix(http): copy native response url to fetch response --- android/capacitor/src/main/assets/native-bridge.js | 8 ++++++++ core/native-bridge.ts | 9 +++++++++ ios/Capacitor/Capacitor/assets/native-bridge.js | 8 ++++++++ 3 files changed, 25 insertions(+) diff --git a/android/capacitor/src/main/assets/native-bridge.js b/android/capacitor/src/main/assets/native-bridge.js index 0a3a1f1974..9171e50583 100644 --- a/android/capacitor/src/main/assets/native-bridge.js +++ b/android/capacitor/src/main/assets/native-bridge.js @@ -392,6 +392,14 @@ var nativeBridge = (function (exports) { headers: nativeResponse.headers, status: nativeResponse.status, }); + /* + * copy url to response, `cordova-plugin-ionic` uses this url from the response + * we need `Object.defineProperty` because url is an inherited getter on the Response + * see: https://stackoverflow.com/a/57382543 + * */ + Object.defineProperty(response, 'url', { + value: nativeResponse.url, + }); console.timeEnd(tag); return response; } diff --git a/core/native-bridge.ts b/core/native-bridge.ts index 3138893271..97ced31a64 100644 --- a/core/native-bridge.ts +++ b/core/native-bridge.ts @@ -447,6 +447,15 @@ const initBridge = (w: any): void => { status: nativeResponse.status, }); + /* + * copy url to response, `cordova-plugin-ionic` uses this url from the response + * we need `Object.defineProperty` because url is an inherited getter on the Response + * see: https://stackoverflow.com/a/57382543 + * */ + Object.defineProperty(response, 'url', { + value: nativeResponse.url, + }); + console.timeEnd(tag); return response; } catch (error) { diff --git a/ios/Capacitor/Capacitor/assets/native-bridge.js b/ios/Capacitor/Capacitor/assets/native-bridge.js index 0a3a1f1974..9171e50583 100644 --- a/ios/Capacitor/Capacitor/assets/native-bridge.js +++ b/ios/Capacitor/Capacitor/assets/native-bridge.js @@ -392,6 +392,14 @@ var nativeBridge = (function (exports) { headers: nativeResponse.headers, status: nativeResponse.status, }); + /* + * copy url to response, `cordova-plugin-ionic` uses this url from the response + * we need `Object.defineProperty` because url is an inherited getter on the Response + * see: https://stackoverflow.com/a/57382543 + * */ + Object.defineProperty(response, 'url', { + value: nativeResponse.url, + }); console.timeEnd(tag); return response; }