From 7119fcde9f725b5ab87902b0790dab63acb3d633 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Tue, 11 Jun 2024 16:48:36 +0200 Subject: [PATCH] fix(http): don't override readyState for non POST requests (#7488) --- .../src/main/assets/native-bridge.js | 27 ++++++++++--------- core/native-bridge.ts | 27 +++++++++---------- .../Capacitor/assets/native-bridge.js | 27 ++++++++++--------- 3 files changed, 41 insertions(+), 40 deletions(-) diff --git a/android/capacitor/src/main/assets/native-bridge.js b/android/capacitor/src/main/assets/native-bridge.js index d255c322cb..8d458087c1 100644 --- a/android/capacitor/src/main/assets/native-bridge.js +++ b/android/capacitor/src/main/assets/native-bridge.js @@ -569,20 +569,7 @@ var nativeBridge = (function (exports) { value: xhr.method, writable: true, }, - readyState: { - get: function () { - var _a; - return (_a = this._readyState) !== null && _a !== void 0 ? _a : 0; - }, - set: function (val) { - this._readyState = val; - setTimeout(() => { - this.dispatchEvent(new Event('readystatechange')); - }); - }, - }, }); - xhr.readyState = 0; const prototype = win.CapacitorWebXMLHttpRequest.prototype; const isProgressEventAvailable = () => typeof ProgressEvent !== 'undefined' && ProgressEvent.prototype instanceof Event; @@ -612,6 +599,20 @@ var nativeBridge = (function (exports) { this._url = createProxyUrl(this._url, win); return win.CapacitorWebXMLHttpRequest.open.call(this, method, this._url); } + Object.defineProperties(this, { + readyState: { + get: function () { + var _a; + return (_a = this._readyState) !== null && _a !== void 0 ? _a : 0; + }, + set: function (val) { + this._readyState = val; + setTimeout(() => { + this.dispatchEvent(new Event('readystatechange')); + }); + }, + }, + }); setTimeout(() => { this.dispatchEvent(new Event('loadstart')); }); diff --git a/core/native-bridge.ts b/core/native-bridge.ts index 5480e64a73..5bd70017b5 100644 --- a/core/native-bridge.ts +++ b/core/native-bridge.ts @@ -651,20 +651,7 @@ const initBridge = (w: any): void => { value: xhr.method, writable: true, }, - readyState: { - get: function () { - return this._readyState ?? 0; - }, - set: function (val: number) { - this._readyState = val; - setTimeout(() => { - this.dispatchEvent(new Event('readystatechange')); - }); - }, - }, }); - - xhr.readyState = 0; const prototype = win.CapacitorWebXMLHttpRequest.prototype; const isProgressEventAvailable = () => @@ -711,7 +698,19 @@ const initBridge = (w: any): void => { this._url, ); } - + Object.defineProperties(this, { + readyState: { + get: function () { + return this._readyState ?? 0; + }, + set: function (val: number) { + this._readyState = val; + setTimeout(() => { + this.dispatchEvent(new Event('readystatechange')); + }); + }, + }, + }); setTimeout(() => { this.dispatchEvent(new Event('loadstart')); }); diff --git a/ios/Capacitor/Capacitor/assets/native-bridge.js b/ios/Capacitor/Capacitor/assets/native-bridge.js index d255c322cb..8d458087c1 100644 --- a/ios/Capacitor/Capacitor/assets/native-bridge.js +++ b/ios/Capacitor/Capacitor/assets/native-bridge.js @@ -569,20 +569,7 @@ var nativeBridge = (function (exports) { value: xhr.method, writable: true, }, - readyState: { - get: function () { - var _a; - return (_a = this._readyState) !== null && _a !== void 0 ? _a : 0; - }, - set: function (val) { - this._readyState = val; - setTimeout(() => { - this.dispatchEvent(new Event('readystatechange')); - }); - }, - }, }); - xhr.readyState = 0; const prototype = win.CapacitorWebXMLHttpRequest.prototype; const isProgressEventAvailable = () => typeof ProgressEvent !== 'undefined' && ProgressEvent.prototype instanceof Event; @@ -612,6 +599,20 @@ var nativeBridge = (function (exports) { this._url = createProxyUrl(this._url, win); return win.CapacitorWebXMLHttpRequest.open.call(this, method, this._url); } + Object.defineProperties(this, { + readyState: { + get: function () { + var _a; + return (_a = this._readyState) !== null && _a !== void 0 ? _a : 0; + }, + set: function (val) { + this._readyState = val; + setTimeout(() => { + this.dispatchEvent(new Event('readystatechange')); + }); + }, + }, + }); setTimeout(() => { this.dispatchEvent(new Event('loadstart')); });