Skip to content

Commit a56f9b9

Browse files
authored
fix(http): don't override readyState for non POST requests (#7510)
1 parent 7bf365c commit a56f9b9

File tree

3 files changed

+41
-40
lines changed

3 files changed

+41
-40
lines changed

android/capacitor/src/main/assets/native-bridge.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -569,20 +569,7 @@ var nativeBridge = (function (exports) {
569569
value: xhr.method,
570570
writable: true,
571571
},
572-
readyState: {
573-
get: function () {
574-
var _a;
575-
return (_a = this._readyState) !== null && _a !== void 0 ? _a : 0;
576-
},
577-
set: function (val) {
578-
this._readyState = val;
579-
setTimeout(() => {
580-
this.dispatchEvent(new Event('readystatechange'));
581-
});
582-
},
583-
},
584572
});
585-
xhr.readyState = 0;
586573
const prototype = win.CapacitorWebXMLHttpRequest.prototype;
587574
const isProgressEventAvailable = () => typeof ProgressEvent !== 'undefined' &&
588575
ProgressEvent.prototype instanceof Event;
@@ -612,6 +599,20 @@ var nativeBridge = (function (exports) {
612599
this._url = createProxyUrl(this._url, win);
613600
return win.CapacitorWebXMLHttpRequest.open.call(this, method, this._url);
614601
}
602+
Object.defineProperties(this, {
603+
readyState: {
604+
get: function () {
605+
var _a;
606+
return (_a = this._readyState) !== null && _a !== void 0 ? _a : 0;
607+
},
608+
set: function (val) {
609+
this._readyState = val;
610+
setTimeout(() => {
611+
this.dispatchEvent(new Event('readystatechange'));
612+
});
613+
},
614+
},
615+
});
615616
setTimeout(() => {
616617
this.dispatchEvent(new Event('loadstart'));
617618
});

core/native-bridge.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -651,20 +651,7 @@ const initBridge = (w: any): void => {
651651
value: xhr.method,
652652
writable: true,
653653
},
654-
readyState: {
655-
get: function () {
656-
return this._readyState ?? 0;
657-
},
658-
set: function (val: number) {
659-
this._readyState = val;
660-
setTimeout(() => {
661-
this.dispatchEvent(new Event('readystatechange'));
662-
});
663-
},
664-
},
665654
});
666-
667-
xhr.readyState = 0;
668655
const prototype = win.CapacitorWebXMLHttpRequest.prototype;
669656

670657
const isProgressEventAvailable = () =>
@@ -711,7 +698,19 @@ const initBridge = (w: any): void => {
711698
this._url,
712699
);
713700
}
714-
701+
Object.defineProperties(this, {
702+
readyState: {
703+
get: function () {
704+
return this._readyState ?? 0;
705+
},
706+
set: function (val: number) {
707+
this._readyState = val;
708+
setTimeout(() => {
709+
this.dispatchEvent(new Event('readystatechange'));
710+
});
711+
},
712+
},
713+
});
715714
setTimeout(() => {
716715
this.dispatchEvent(new Event('loadstart'));
717716
});

ios/Capacitor/Capacitor/assets/native-bridge.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -569,20 +569,7 @@ var nativeBridge = (function (exports) {
569569
value: xhr.method,
570570
writable: true,
571571
},
572-
readyState: {
573-
get: function () {
574-
var _a;
575-
return (_a = this._readyState) !== null && _a !== void 0 ? _a : 0;
576-
},
577-
set: function (val) {
578-
this._readyState = val;
579-
setTimeout(() => {
580-
this.dispatchEvent(new Event('readystatechange'));
581-
});
582-
},
583-
},
584572
});
585-
xhr.readyState = 0;
586573
const prototype = win.CapacitorWebXMLHttpRequest.prototype;
587574
const isProgressEventAvailable = () => typeof ProgressEvent !== 'undefined' &&
588575
ProgressEvent.prototype instanceof Event;
@@ -612,6 +599,20 @@ var nativeBridge = (function (exports) {
612599
this._url = createProxyUrl(this._url, win);
613600
return win.CapacitorWebXMLHttpRequest.open.call(this, method, this._url);
614601
}
602+
Object.defineProperties(this, {
603+
readyState: {
604+
get: function () {
605+
var _a;
606+
return (_a = this._readyState) !== null && _a !== void 0 ? _a : 0;
607+
},
608+
set: function (val) {
609+
this._readyState = val;
610+
setTimeout(() => {
611+
this.dispatchEvent(new Event('readystatechange'));
612+
});
613+
},
614+
},
615+
});
615616
setTimeout(() => {
616617
this.dispatchEvent(new Event('loadstart'));
617618
});

0 commit comments

Comments
 (0)