diff --git a/android/capacitor/src/main/assets/native-bridge.js b/android/capacitor/src/main/assets/native-bridge.js index 6a9227f031..dc29bb28f1 100644 --- a/android/capacitor/src/main/assets/native-bridge.js +++ b/android/capacitor/src/main/assets/native-bridge.js @@ -142,11 +142,13 @@ var nativeBridge = (function (exports) { var _a, _b; if (isRelativeOrProxyUrl(url)) return url; - let proxyUrl = new URL(url); + const proxyUrl = new URL(url); + const bridgeUrl = new URL((_b = (_a = win.Capacitor) === null || _a === void 0 ? void 0 : _a.getServerUrl()) !== null && _b !== void 0 ? _b : ''); const isHttps = proxyUrl.protocol === 'https:'; const originalHost = encodeURIComponent(proxyUrl.host); const originalPathname = proxyUrl.pathname; - proxyUrl = new URL((_b = (_a = win.Capacitor) === null || _a === void 0 ? void 0 : _a.getServerUrl()) !== null && _b !== void 0 ? _b : ''); + proxyUrl.protocol = bridgeUrl.protocol; + proxyUrl.host = bridgeUrl.host; proxyUrl.pathname = `${isHttps ? CAPACITOR_HTTPS_INTERCEPTOR : CAPACITOR_HTTP_INTERCEPTOR}/${originalHost}${originalPathname}`; return proxyUrl.toString(); }; diff --git a/core/native-bridge.ts b/core/native-bridge.ts index 6660875590..a557fed405 100644 --- a/core/native-bridge.ts +++ b/core/native-bridge.ts @@ -132,12 +132,13 @@ const isRelativeOrProxyUrl = (url: string | undefined): boolean => const createProxyUrl = (url: string, win: WindowCapacitor): string => { if (isRelativeOrProxyUrl(url)) return url; - let proxyUrl = new URL(url); + const proxyUrl = new URL(url); + const bridgeUrl = new URL(win.Capacitor?.getServerUrl() ?? ''); const isHttps = proxyUrl.protocol === 'https:'; const originalHost = encodeURIComponent(proxyUrl.host); const originalPathname = proxyUrl.pathname; - proxyUrl = new URL(win.Capacitor?.getServerUrl() ?? ''); - + proxyUrl.protocol = bridgeUrl.protocol; + proxyUrl.host = bridgeUrl.host; proxyUrl.pathname = `${ isHttps ? CAPACITOR_HTTPS_INTERCEPTOR : CAPACITOR_HTTP_INTERCEPTOR }/${originalHost}${originalPathname}`; diff --git a/ios/Capacitor/Capacitor/assets/native-bridge.js b/ios/Capacitor/Capacitor/assets/native-bridge.js index 6a9227f031..dc29bb28f1 100644 --- a/ios/Capacitor/Capacitor/assets/native-bridge.js +++ b/ios/Capacitor/Capacitor/assets/native-bridge.js @@ -142,11 +142,13 @@ var nativeBridge = (function (exports) { var _a, _b; if (isRelativeOrProxyUrl(url)) return url; - let proxyUrl = new URL(url); + const proxyUrl = new URL(url); + const bridgeUrl = new URL((_b = (_a = win.Capacitor) === null || _a === void 0 ? void 0 : _a.getServerUrl()) !== null && _b !== void 0 ? _b : ''); const isHttps = proxyUrl.protocol === 'https:'; const originalHost = encodeURIComponent(proxyUrl.host); const originalPathname = proxyUrl.pathname; - proxyUrl = new URL((_b = (_a = win.Capacitor) === null || _a === void 0 ? void 0 : _a.getServerUrl()) !== null && _b !== void 0 ? _b : ''); + proxyUrl.protocol = bridgeUrl.protocol; + proxyUrl.host = bridgeUrl.host; proxyUrl.pathname = `${isHttps ? CAPACITOR_HTTPS_INTERCEPTOR : CAPACITOR_HTTP_INTERCEPTOR}/${originalHost}${originalPathname}`; return proxyUrl.toString(); };