Skip to content

Commit

Permalink
fix(http): don't override readyState for non POST requests (#7510)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile committed Jun 11, 2024
1 parent 7bf365c commit a56f9b9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 40 deletions.
27 changes: 14 additions & 13 deletions android/capacitor/src/main/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'));
});
Expand Down
27 changes: 13 additions & 14 deletions core/native-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () =>
Expand Down Expand Up @@ -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'));
});
Expand Down
27 changes: 14 additions & 13 deletions ios/Capacitor/Capacitor/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'));
});
Expand Down

0 comments on commit a56f9b9

Please sign in to comment.