Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(http): don't override readyState for non POST requests #7510

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading