Skip to content

Commit

Permalink
fix(ios/android): copy url from nativeResponse to response (#6482)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Apr 11, 2023
1 parent 9447fc3 commit 828fb71
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
15 changes: 11 additions & 4 deletions android/capacitor/src/main/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ var nativeBridge = (function (exports) {
headers: nativeResponse.headers,
status: nativeResponse.status,
});
/*
* copy url to response, `cordova-plugin-ionic` uses this url from the response
* we need `Object.defineProperty` because url is an inherited getter on the Response
* see: https://stackoverflow.com/a/57382543
* */
Object.defineProperty(response, 'url', {
value: nativeResponse.url,
});
console.timeEnd(tag);
return response;
}
Expand Down Expand Up @@ -525,10 +533,9 @@ var nativeBridge = (function (exports) {
this._headers = nativeResponse.headers;
this.status = nativeResponse.status;
this.response = nativeResponse.data;
this.responseText =
!nativeResponse.headers['Content-Type'].startsWith('application/json')
? nativeResponse.data
: JSON.stringify(nativeResponse.data);
this.responseText = !nativeResponse.headers['Content-Type'].startsWith('application/json')
? nativeResponse.data
: JSON.stringify(nativeResponse.data);
this.responseURL = nativeResponse.url;
this.readyState = 4;
this.dispatchEvent(new Event('load'));
Expand Down
15 changes: 11 additions & 4 deletions ios/Capacitor/Capacitor/assets/native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ var nativeBridge = (function (exports) {
headers: nativeResponse.headers,
status: nativeResponse.status,
});
/*
* copy url to response, `cordova-plugin-ionic` uses this url from the response
* we need `Object.defineProperty` because url is an inherited getter on the Response
* see: https://stackoverflow.com/a/57382543
* */
Object.defineProperty(response, 'url', {
value: nativeResponse.url,
});
console.timeEnd(tag);
return response;
}
Expand Down Expand Up @@ -525,10 +533,9 @@ var nativeBridge = (function (exports) {
this._headers = nativeResponse.headers;
this.status = nativeResponse.status;
this.response = nativeResponse.data;
this.responseText =
!nativeResponse.headers['Content-Type'].startsWith('application/json')
? nativeResponse.data
: JSON.stringify(nativeResponse.data);
this.responseText = !nativeResponse.headers['Content-Type'].startsWith('application/json')
? nativeResponse.data
: JSON.stringify(nativeResponse.data);
this.responseURL = nativeResponse.url;
this.readyState = 4;
this.dispatchEvent(new Event('load'));
Expand Down

0 comments on commit 828fb71

Please sign in to comment.