@fellow/capacitor-android
Advanced tools
Comparing version 3.5.1-beta.4 to 5.1.1-beta.1
@@ -5,5 +5,32 @@ | ||
const nativeBridge = (function (exports) { | ||
var nativeBridge = (function (exports) { | ||
'use strict'; | ||
var ExceptionCode; | ||
(function (ExceptionCode) { | ||
/** | ||
* API is not implemented. | ||
* | ||
* This usually means the API can't be used because it is not implemented for | ||
* the current platform. | ||
*/ | ||
ExceptionCode["Unimplemented"] = "UNIMPLEMENTED"; | ||
/** | ||
* API is not available. | ||
* | ||
* This means the API can't be used right now because: | ||
* - it is currently missing a prerequisite, such as network connectivity | ||
* - it requires a particular platform or browser version | ||
*/ | ||
ExceptionCode["Unavailable"] = "UNAVAILABLE"; | ||
})(ExceptionCode || (ExceptionCode = {})); | ||
class CapacitorException extends Error { | ||
constructor(message, code, data) { | ||
super(message); | ||
this.message = message; | ||
this.code = code; | ||
this.data = data; | ||
} | ||
} | ||
// For removing exports for iOS/Android, keep let for reassignment | ||
@@ -113,3 +140,4 @@ // eslint-disable-next-line | ||
nav.app.exitApp = () => { | ||
if (!cap.Plugins || !cap.Plugins.App) { | ||
var _a; | ||
if (!((_a = cap.Plugins) === null || _a === void 0 ? void 0 : _a.App)) { | ||
win.console.warn('App plugin not installed'); | ||
@@ -125,2 +153,3 @@ } | ||
doc.addEventListener = (...args) => { | ||
var _a; | ||
const eventName = args[0]; | ||
@@ -134,3 +163,3 @@ const handler = args[1]; | ||
// back button action | ||
if (!cap.Plugins || !cap.Plugins.App) { | ||
if (!((_a = cap.Plugins) === null || _a === void 0 ? void 0 : _a.App)) { | ||
win.console.warn('App plugin not installed'); | ||
@@ -248,2 +277,327 @@ } | ||
}; | ||
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'); | ||
let doPatchCookies = false; | ||
// check if capacitor cookies is disabled before patching | ||
if (platform === 'ios') { | ||
// Use prompt to synchronously get capacitor cookies config. | ||
// https://stackoverflow.com/questions/29249132/wkwebview-complex-communication-between-javascript-native-code/49474323#49474323 | ||
const payload = { | ||
type: 'CapacitorCookies.isEnabled', | ||
}; | ||
const isCookiesEnabled = prompt(JSON.stringify(payload)); | ||
if (isCookiesEnabled === 'true') { | ||
doPatchCookies = true; | ||
} | ||
} | ||
else if (typeof win.CapacitorCookiesAndroidInterface !== 'undefined') { | ||
const isCookiesEnabled = win.CapacitorCookiesAndroidInterface.isEnabled(); | ||
if (isCookiesEnabled === true) { | ||
doPatchCookies = true; | ||
} | ||
} | ||
if (doPatchCookies) { | ||
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.get', | ||
}; | ||
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(';'); | ||
const domainSection = val.toLowerCase().split('domain=')[1]; | ||
const domain = cookiePairs.length > 1 && | ||
domainSection != null && | ||
domainSection.length > 0 | ||
? domainSection.split(';')[0].trim() | ||
: ''; | ||
if (platform === 'ios') { | ||
// Use prompt to synchronously set cookies. | ||
// https://stackoverflow.com/questions/29249132/wkwebview-complex-communication-between-javascript-native-code/49474323#49474323 | ||
const payload = { | ||
type: 'CapacitorCookies.set', | ||
action: val, | ||
domain, | ||
}; | ||
prompt(JSON.stringify(payload)); | ||
} | ||
else if (typeof win.CapacitorCookiesAndroidInterface !== 'undefined') { | ||
win.CapacitorCookiesAndroidInterface.setCookie(domain, val); | ||
} | ||
}, | ||
}); | ||
} | ||
// patch fetch / XHR on Android/iOS | ||
// store original fetch & XHR functions | ||
win.CapacitorWebFetch = window.fetch; | ||
win.CapacitorWebXMLHttpRequest = { | ||
abort: window.XMLHttpRequest.prototype.abort, | ||
getAllResponseHeaders: window.XMLHttpRequest.prototype.getAllResponseHeaders, | ||
getResponseHeader: window.XMLHttpRequest.prototype.getResponseHeader, | ||
open: window.XMLHttpRequest.prototype.open, | ||
send: window.XMLHttpRequest.prototype.send, | ||
setRequestHeader: window.XMLHttpRequest.prototype.setRequestHeader, | ||
}; | ||
let doPatchHttp = false; | ||
// check if capacitor http is disabled before patching | ||
if (platform === 'ios') { | ||
// Use prompt to synchronously get capacitor http config. | ||
// https://stackoverflow.com/questions/29249132/wkwebview-complex-communication-between-javascript-native-code/49474323#49474323 | ||
const payload = { | ||
type: 'CapacitorHttp', | ||
}; | ||
const isHttpEnabled = prompt(JSON.stringify(payload)); | ||
if (isHttpEnabled === 'true') { | ||
doPatchHttp = true; | ||
} | ||
} | ||
else if (typeof win.CapacitorHttpAndroidInterface !== 'undefined') { | ||
const isHttpEnabled = win.CapacitorHttpAndroidInterface.isEnabled(); | ||
if (isHttpEnabled === true) { | ||
doPatchHttp = true; | ||
} | ||
} | ||
if (doPatchHttp) { | ||
// fetch patch | ||
window.fetch = async (resource, options) => { | ||
var _a; | ||
if (!(resource.toString().startsWith('http:') || | ||
resource.toString().startsWith('https:'))) { | ||
return win.CapacitorWebFetch(resource, options); | ||
} | ||
const tag = `CapacitorHttp fetch ${Date.now()} ${resource}`; | ||
console.time(tag); | ||
try { | ||
// intercept request & pass to the bridge | ||
let headers = options === null || options === void 0 ? void 0 : options.headers; | ||
if ((options === null || options === void 0 ? void 0 : options.headers) instanceof Headers) { | ||
headers = Object.fromEntries(options.headers.entries()); | ||
} | ||
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: headers, | ||
}); | ||
let data = ((_a = nativeResponse.headers['Content-Type']) === null || _a === void 0 ? void 0 : _a.startsWith('application/json')) | ||
? JSON.stringify(nativeResponse.data) : nativeResponse.data; | ||
// use null data for 204 No Content HTTP response | ||
if (nativeResponse.status === 204) { | ||
data = null; | ||
} | ||
// intercept & parse response before returning | ||
const response = new Response(data, { | ||
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; | ||
} | ||
catch (error) { | ||
console.timeEnd(tag); | ||
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 () { | ||
if (this._url == null || | ||
!(this._url.startsWith('http:') || this._url.startsWith('https:'))) { | ||
return win.CapacitorWebXMLHttpRequest.abort.call(this); | ||
} | ||
this.readyState = 0; | ||
this.dispatchEvent(new Event('abort')); | ||
this.dispatchEvent(new Event('loadend')); | ||
}; | ||
// XHR patch open | ||
window.XMLHttpRequest.prototype.open = function (method, url) { | ||
this._url = url; | ||
if (!(url.startsWith('http:') || url.toString().startsWith('https:'))) { | ||
return win.CapacitorWebXMLHttpRequest.open.call(this, method, url); | ||
} | ||
Object.defineProperties(this, { | ||
_headers: { | ||
value: {}, | ||
writable: true, | ||
}, | ||
_method: { | ||
value: method, | ||
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, | ||
}, | ||
}); | ||
addEventListeners.call(this); | ||
this.readyState = 1; | ||
}; | ||
// XHR patch set request header | ||
window.XMLHttpRequest.prototype.setRequestHeader = function (header, value) { | ||
if (this._url == null || | ||
!(this._url.startsWith('http:') || this._url.startsWith('https:'))) { | ||
return win.CapacitorWebXMLHttpRequest.setRequestHeader.call(this, header, value); | ||
} | ||
this._headers[header] = value; | ||
}; | ||
// XHR patch send | ||
window.XMLHttpRequest.prototype.send = function (body) { | ||
if (this._url == null || | ||
!(this._url.startsWith('http:') || this._url.startsWith('https:'))) { | ||
return win.CapacitorWebXMLHttpRequest.send.call(this, body); | ||
} | ||
const tag = `CapacitorHttp XMLHttpRequest ${Date.now()} ${this._url}`; | ||
console.time(tag); | ||
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 != null && Object.keys(this._headers).length > 0 | ||
? this._headers | ||
: undefined, | ||
}) | ||
.then((nativeResponse) => { | ||
var _a; | ||
// intercept & parse response before returning | ||
if (this.readyState == 2) { | ||
this.dispatchEvent(new Event('loadstart')); | ||
this._headers = nativeResponse.headers; | ||
this.status = nativeResponse.status; | ||
this.response = nativeResponse.data; | ||
this.responseText = ((_a = nativeResponse.headers['Content-Type']) === null || _a === void 0 ? void 0 : _a.startsWith('application/json')) | ||
? JSON.stringify(nativeResponse.data) : nativeResponse.data; | ||
this.responseURL = nativeResponse.url; | ||
this.readyState = 4; | ||
this.dispatchEvent(new Event('load')); | ||
this.dispatchEvent(new Event('loadend')); | ||
} | ||
console.timeEnd(tag); | ||
}) | ||
.catch((error) => { | ||
this.dispatchEvent(new Event('loadstart')); | ||
this.status = error.status; | ||
this._headers = error.headers; | ||
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')); | ||
console.timeEnd(tag); | ||
}); | ||
} | ||
catch (error) { | ||
this.dispatchEvent(new Event('loadstart')); | ||
this.status = 500; | ||
this._headers = {}; | ||
this.response = error; | ||
this.responseText = error.toString(); | ||
this.responseURL = this._url; | ||
this.readyState = 4; | ||
this.dispatchEvent(new Event('error')); | ||
this.dispatchEvent(new Event('loadend')); | ||
console.timeEnd(tag); | ||
} | ||
}; | ||
// XHR patch getAllResponseHeaders | ||
window.XMLHttpRequest.prototype.getAllResponseHeaders = function () { | ||
if (this._url == null || | ||
!(this._url.startsWith('http:') || this._url.startsWith('https:'))) { | ||
return win.CapacitorWebXMLHttpRequest.getAllResponseHeaders.call(this); | ||
} | ||
let returnString = ''; | ||
for (const key in this._headers) { | ||
if (key != 'Set-Cookie') { | ||
returnString += key + ': ' + this._headers[key] + '\r\n'; | ||
} | ||
} | ||
return returnString; | ||
}; | ||
// XHR patch getResponseHeader | ||
window.XMLHttpRequest.prototype.getResponseHeader = function (name) { | ||
if (this._url == null || | ||
!(this._url.startsWith('http:') || this._url.startsWith('https:'))) { | ||
return win.CapacitorWebXMLHttpRequest.getResponseHeader.call(this, name); | ||
} | ||
return this._headers[name]; | ||
}; | ||
} | ||
} | ||
// patch window.console on iOS and store original console fns | ||
@@ -392,2 +746,7 @@ const isIos = getPlatformId(win) === 'ios'; | ||
}; | ||
if (win === null || win === void 0 ? void 0 : win.androidBridge) { | ||
win.androidBridge.onmessage = function (event) { | ||
returnResult(JSON.parse(event.data)); | ||
}; | ||
} | ||
/** | ||
@@ -397,2 +756,5 @@ * Process a response from the native layer. | ||
cap.fromNative = result => { | ||
returnResult(result); | ||
}; | ||
const returnResult = (result) => { | ||
var _a, _b; | ||
@@ -470,2 +832,3 @@ if (cap.isLoggingEnabled && result.pluginId !== 'Console') { | ||
cap.withPlugin = (_pluginId, _fn) => dummy; | ||
cap.Exception = CapacitorException; | ||
initEvents(win, cap); | ||
@@ -472,0 +835,0 @@ initLegacyHandlers(win, cap); |
{ | ||
"name": "@fellow/capacitor-android", | ||
"version": "3.5.1-beta.4", | ||
"version": "5.1.1-beta.1", | ||
"description": "Capacitor: Cross-platform apps with JavaScript and the web", | ||
@@ -10,3 +10,3 @@ "homepage": "https://capacitorjs.com", | ||
"type": "git", | ||
"url": "git+https://github.com/fellowapp/capacitor.git#fellow-fork-3.x", | ||
"url": "git+https://github.com/fellowapp/capacitor.git#fellow-fork-5.x", | ||
"directory": "android" | ||
@@ -21,2 +21,3 @@ }, | ||
"capacitor/lint.xml", | ||
"capacitor/proguard-rules.pro", | ||
"capacitor/src/main/" | ||
@@ -28,3 +29,3 @@ ], | ||
"peerDependencies": { | ||
"@capacitor/core": "^3.5.0" | ||
"@capacitor/core": "^5.1.0" | ||
}, | ||
@@ -31,0 +32,0 @@ "publishConfig": { |
# About this fork | ||
This is a fork of the Capacitor Android platfrom that modifies the injection mechanic to trigger based on webview events to allow for compatibility with service workers. | ||
This is a fork of the Capacitor Android platform that modifies the injection mechanic to trigger based on webview events to allow for compatibility with service workers. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
402608
75
841