Socket
Socket
Sign inDemoInstall

@capacitor/ios

Package Overview
Dependencies
Maintainers
12
Versions
751
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@capacitor/ios - npm Package Compare versions

Comparing version 4.1.1-dev-c03a33d3-20220907T1152.0 to 4.1.1-nightly-20220908T150529.0

203

Capacitor/Capacitor/assets/native-bridge.js

@@ -244,205 +244,2 @@

};
/**
* Safely web decode a string value (inspired by js-cookie)
* @param str The string value to decode
*/
const decode = (str) => str.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
const platform = getPlatformId(win);
if (platform == 'android' || platform == 'ios') {
// patch document.cookie on Android/iOS
win.CapacitorCookiesDescriptor =
Object.getOwnPropertyDescriptor(Document.prototype, 'cookie') ||
Object.getOwnPropertyDescriptor(HTMLDocument.prototype, 'cookie');
Object.defineProperty(document, 'cookie', {
get: function () {
if (platform === 'ios') {
// Use prompt to synchronously get cookies.
// https://stackoverflow.com/questions/29249132/wkwebview-complex-communication-between-javascript-native-code/49474323#49474323
const payload = {
type: 'CapacitorCookies',
};
const res = prompt(JSON.stringify(payload));
return res;
}
else if (typeof win.CapacitorCookiesAndroidInterface !== 'undefined') {
return win.CapacitorCookiesAndroidInterface.getCookies();
}
},
set: function (val) {
const cookiePairs = val.split(';');
for (const cookiePair of cookiePairs) {
const cookieKey = cookiePair.split('=')[0];
const cookieValue = cookiePair.split('=')[1];
if (null == cookieValue) {
continue;
}
cap.toNative('CapacitorCookies', 'setCookie', {
key: cookieKey,
value: decode(cookieValue),
});
}
},
});
// patch fetch / XHR on Android/iOS
// store original fetch & XHR functions
win.CapacitorWebFetch = window.fetch;
win.CapacitorWebXMLHttpRequest = {
abort: window.XMLHttpRequest.prototype.abort,
open: window.XMLHttpRequest.prototype.open,
send: window.XMLHttpRequest.prototype.send,
setRequestHeader: window.XMLHttpRequest.prototype.setRequestHeader,
};
// fetch patch
window.fetch = async (resource, options) => {
if (resource.toString().startsWith('data:')) {
return win.CapacitorWebFetch(resource, options);
}
try {
// intercept request & pass to the bridge
const nativeResponse = await cap.nativePromise('CapacitorHttp', 'request', {
url: resource,
method: (options === null || options === void 0 ? void 0 : options.method) ? options.method : undefined,
data: (options === null || options === void 0 ? void 0 : options.body) ? options.body : undefined,
headers: (options === null || options === void 0 ? void 0 : options.headers) ? options.headers : undefined,
});
// intercept & parse response before returning
const response = new Response(JSON.stringify(nativeResponse.data), {
headers: nativeResponse.headers,
status: nativeResponse.status,
});
return response;
}
catch (error) {
return Promise.reject(error);
}
};
// XHR event listeners
const addEventListeners = function () {
this.addEventListener('abort', function () {
if (typeof this.onabort === 'function')
this.onabort();
});
this.addEventListener('error', function () {
if (typeof this.onerror === 'function')
this.onerror();
});
this.addEventListener('load', function () {
if (typeof this.onload === 'function')
this.onload();
});
this.addEventListener('loadend', function () {
if (typeof this.onloadend === 'function')
this.onloadend();
});
this.addEventListener('loadstart', function () {
if (typeof this.onloadstart === 'function')
this.onloadstart();
});
this.addEventListener('readystatechange', function () {
if (typeof this.onreadystatechange === 'function')
this.onreadystatechange();
});
this.addEventListener('timeout', function () {
if (typeof this.ontimeout === 'function')
this.ontimeout();
});
};
// XHR patch abort
window.XMLHttpRequest.prototype.abort = function () {
Object.defineProperties(this, {
_headers: {
value: {},
writable: true,
},
readyState: {
get: function () {
var _a;
return (_a = this._readyState) !== null && _a !== void 0 ? _a : 0;
},
set: function (val) {
this._readyState = val;
this.dispatchEvent(new Event('readystatechange'));
},
},
response: {
value: '',
writable: true,
},
responseText: {
value: '',
writable: true,
},
responseURL: {
value: '',
writable: true,
},
status: {
value: 0,
writable: true,
},
});
this.readyState = 0;
this.dispatchEvent(new Event('abort'));
this.dispatchEvent(new Event('loadend'));
};
// XHR patch open
window.XMLHttpRequest.prototype.open = function (method, url) {
this.abort();
addEventListeners.call(this);
this._method = method;
this._url = url;
this.readyState = 1;
};
// XHR patch set request header
window.XMLHttpRequest.prototype.setRequestHeader = function (header, value) {
this._headers[header] = value;
};
// XHR patch send
window.XMLHttpRequest.prototype.send = function (body) {
try {
this.readyState = 2;
// intercept request & pass to the bridge
cap
.nativePromise('CapacitorHttp', 'request', {
url: this._url,
method: this._method,
data: body !== null ? body : undefined,
headers: this._headers,
})
.then((nativeResponse) => {
// intercept & parse response before returning
if (this.readyState == 2) {
this.dispatchEvent(new Event('loadstart'));
this.status = nativeResponse.status;
this.response = nativeResponse.data;
this.responseText = JSON.stringify(nativeResponse.data);
this.responseURL = nativeResponse.url;
this.readyState = 4;
this.dispatchEvent(new Event('load'));
this.dispatchEvent(new Event('loadend'));
}
})
.catch((error) => {
this.dispatchEvent(new Event('loadstart'));
this.status = error.status;
this.response = error.data;
this.responseText = JSON.stringify(error.data);
this.responseURL = error.url;
this.readyState = 4;
this.dispatchEvent(new Event('error'));
this.dispatchEvent(new Event('loadend'));
});
}
catch (error) {
this.dispatchEvent(new Event('loadstart'));
this.status = 500;
this.response = error;
this.responseText = error.toString();
this.responseURL = this._url;
this.readyState = 4;
this.dispatchEvent(new Event('error'));
this.dispatchEvent(new Event('loadend'));
}
};
}
// patch window.console on iOS and store original console fns

@@ -449,0 +246,0 @@ const isIos = getPlatformId(win) === 'ios';

4

package.json
{
"name": "@capacitor/ios",
"version": "4.1.1-dev-c03a33d3-20220907T1152.0",
"version": "4.1.1-nightly-20220908T150529.0",
"description": "Capacitor: Cross-platform apps with JavaScript and the web",

@@ -33,3 +33,3 @@ "homepage": "https://capacitorjs.com",

},
"gitHead": "c03a33d3a479db6e3897d70245d9803998acb6d6"
"gitHead": "17fbabb2a77d1b356d24048efc5883bd4d049104"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc