@capacitor/ios 4.1.1-dev-7e3589f9.0 → 4.1.1-dev-637db572-20220913T1704.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -244,7 +244,7 @@ internal class WebViewDelegationHandler: NSObject, WKNavigationDelegate, WKUIDel
|
|
|
244
244
|
|
|
245
245
|
public func webView(_ webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String, defaultText: String?, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (String?) -> Void) {
|
|
246
246
|
|
|
247
|
-
// Check if this is synchronous cookie call
|
|
247
|
+
// Check if this is synchronous cookie or http call
|
|
248
248
|
do {
|
|
249
249
|
if let dataFromString = prompt.data(using: .utf8, allowLossyConversion: false) {
|
|
250
250
|
if let payload = try JSONSerialization.jsonObject(with: dataFromString, options: .fragmentsAllowed) as? [String: AnyObject] {
|
|
@@ -254,6 +254,11 @@ internal class WebViewDelegationHandler: NSObject, WKNavigationDelegate, WKUIDel
|
|
|
254
254
|
completionHandler(CapacitorCookieManager(bridge!.config).getCookies())
|
|
255
255
|
// Don't present prompt
|
|
256
256
|
return
|
|
257
|
+
} else if type == "CapacitorHttp" {
|
|
258
|
+
let pluginConfig = bridge!.config.getPluginConfig("CapacitorHttp")
|
|
259
|
+
completionHandler(String(pluginConfig.getBoolean("disabled", false)))
|
|
260
|
+
// Don't present prompt
|
|
261
|
+
return
|
|
257
262
|
}
|
|
258
263
|
}
|
|
259
264
|
}
|
|
@@ -291,158 +291,178 @@ const nativeBridge = (function (exports) {
|
|
|
291
291
|
send: window.XMLHttpRequest.prototype.send,
|
|
292
292
|
setRequestHeader: window.XMLHttpRequest.prototype.setRequestHeader,
|
|
293
293
|
};
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
294
|
+
let doPatchHttp = true;
|
|
295
|
+
// check if capacitor http is disabled before patching
|
|
296
|
+
if (platform === 'ios') {
|
|
297
|
+
// Use prompt to synchronously get capacitor http config.
|
|
298
|
+
// https://stackoverflow.com/questions/29249132/wkwebview-complex-communication-between-javascript-native-code/49474323#49474323
|
|
299
|
+
const payload = {
|
|
300
|
+
type: 'CapacitorHttp',
|
|
301
|
+
};
|
|
302
|
+
const isDisabled = prompt(JSON.stringify(payload));
|
|
303
|
+
if (isDisabled === 'true') {
|
|
304
|
+
doPatchHttp = false;
|
|
298
305
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
+
}
|
|
307
|
+
else if (typeof win.CapacitorHttpAndroidInterface !== 'undefined') {
|
|
308
|
+
const isDisabled = win.CapacitorHttpAndroidInterface.isDisabled();
|
|
309
|
+
if (isDisabled === true) {
|
|
310
|
+
doPatchHttp = false;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (doPatchHttp) {
|
|
314
|
+
// fetch patch
|
|
315
|
+
window.fetch = async (resource, options) => {
|
|
316
|
+
if (resource.toString().startsWith('data:')) {
|
|
317
|
+
return win.CapacitorWebFetch(resource, options);
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
// intercept request & pass to the bridge
|
|
321
|
+
const nativeResponse = await cap.nativePromise('CapacitorHttp', 'request', {
|
|
322
|
+
url: resource,
|
|
323
|
+
method: (options === null || options === void 0 ? void 0 : options.method) ? options.method : undefined,
|
|
324
|
+
data: (options === null || options === void 0 ? void 0 : options.body) ? options.body : undefined,
|
|
325
|
+
headers: (options === null || options === void 0 ? void 0 : options.headers) ? options.headers : undefined,
|
|
326
|
+
});
|
|
327
|
+
// intercept & parse response before returning
|
|
328
|
+
const response = new Response(JSON.stringify(nativeResponse.data), {
|
|
329
|
+
headers: nativeResponse.headers,
|
|
330
|
+
status: nativeResponse.status,
|
|
331
|
+
});
|
|
332
|
+
return response;
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
return Promise.reject(error);
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
// XHR event listeners
|
|
339
|
+
const addEventListeners = function () {
|
|
340
|
+
this.addEventListener('abort', function () {
|
|
341
|
+
if (typeof this.onabort === 'function')
|
|
342
|
+
this.onabort();
|
|
306
343
|
});
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
status: nativeResponse.status,
|
|
344
|
+
this.addEventListener('error', function () {
|
|
345
|
+
if (typeof this.onerror === 'function')
|
|
346
|
+
this.onerror();
|
|
311
347
|
});
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
if (typeof this.ontimeout === 'function')
|
|
346
|
-
this.ontimeout();
|
|
347
|
-
});
|
|
348
|
-
};
|
|
349
|
-
// XHR patch abort
|
|
350
|
-
window.XMLHttpRequest.prototype.abort = function () {
|
|
351
|
-
Object.defineProperties(this, {
|
|
352
|
-
_headers: {
|
|
353
|
-
value: {},
|
|
354
|
-
writable: true,
|
|
355
|
-
},
|
|
356
|
-
readyState: {
|
|
357
|
-
get: function () {
|
|
358
|
-
var _a;
|
|
359
|
-
return (_a = this._readyState) !== null && _a !== void 0 ? _a : 0;
|
|
348
|
+
this.addEventListener('load', function () {
|
|
349
|
+
if (typeof this.onload === 'function')
|
|
350
|
+
this.onload();
|
|
351
|
+
});
|
|
352
|
+
this.addEventListener('loadend', function () {
|
|
353
|
+
if (typeof this.onloadend === 'function')
|
|
354
|
+
this.onloadend();
|
|
355
|
+
});
|
|
356
|
+
this.addEventListener('loadstart', function () {
|
|
357
|
+
if (typeof this.onloadstart === 'function')
|
|
358
|
+
this.onloadstart();
|
|
359
|
+
});
|
|
360
|
+
this.addEventListener('readystatechange', function () {
|
|
361
|
+
if (typeof this.onreadystatechange === 'function')
|
|
362
|
+
this.onreadystatechange();
|
|
363
|
+
});
|
|
364
|
+
this.addEventListener('timeout', function () {
|
|
365
|
+
if (typeof this.ontimeout === 'function')
|
|
366
|
+
this.ontimeout();
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
// XHR patch abort
|
|
370
|
+
window.XMLHttpRequest.prototype.abort = function () {
|
|
371
|
+
this.readyState = 0;
|
|
372
|
+
this.dispatchEvent(new Event('abort'));
|
|
373
|
+
this.dispatchEvent(new Event('loadend'));
|
|
374
|
+
};
|
|
375
|
+
// XHR patch open
|
|
376
|
+
window.XMLHttpRequest.prototype.open = function (method, url) {
|
|
377
|
+
Object.defineProperties(this, {
|
|
378
|
+
_headers: {
|
|
379
|
+
value: {},
|
|
380
|
+
writable: true,
|
|
360
381
|
},
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
382
|
+
readyState: {
|
|
383
|
+
get: function () {
|
|
384
|
+
var _a;
|
|
385
|
+
return (_a = this._readyState) !== null && _a !== void 0 ? _a : 0;
|
|
386
|
+
},
|
|
387
|
+
set: function (val) {
|
|
388
|
+
this._readyState = val;
|
|
389
|
+
this.dispatchEvent(new Event('readystatechange'));
|
|
390
|
+
},
|
|
364
391
|
},
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
392
|
+
response: {
|
|
393
|
+
value: '',
|
|
394
|
+
writable: true,
|
|
395
|
+
},
|
|
396
|
+
responseText: {
|
|
397
|
+
value: '',
|
|
398
|
+
writable: true,
|
|
399
|
+
},
|
|
400
|
+
responseURL: {
|
|
401
|
+
value: '',
|
|
402
|
+
writable: true,
|
|
403
|
+
},
|
|
404
|
+
status: {
|
|
405
|
+
value: 0,
|
|
406
|
+
writable: true,
|
|
407
|
+
},
|
|
408
|
+
});
|
|
409
|
+
addEventListeners.call(this);
|
|
410
|
+
this._method = method;
|
|
411
|
+
this._url = url;
|
|
412
|
+
this.readyState = 1;
|
|
413
|
+
};
|
|
414
|
+
// XHR patch set request header
|
|
415
|
+
window.XMLHttpRequest.prototype.setRequestHeader = function (header, value) {
|
|
416
|
+
this._headers[header] = value;
|
|
417
|
+
};
|
|
418
|
+
// XHR patch send
|
|
419
|
+
window.XMLHttpRequest.prototype.send = function (body) {
|
|
420
|
+
try {
|
|
421
|
+
this.readyState = 2;
|
|
422
|
+
// intercept request & pass to the bridge
|
|
423
|
+
cap
|
|
424
|
+
.nativePromise('CapacitorHttp', 'request', {
|
|
425
|
+
url: this._url,
|
|
426
|
+
method: this._method,
|
|
427
|
+
data: body !== null ? body : undefined,
|
|
428
|
+
headers: this._headers,
|
|
429
|
+
})
|
|
430
|
+
.then((nativeResponse) => {
|
|
431
|
+
// intercept & parse response before returning
|
|
432
|
+
if (this.readyState == 2) {
|
|
433
|
+
this.dispatchEvent(new Event('loadstart'));
|
|
434
|
+
this.status = nativeResponse.status;
|
|
435
|
+
this.response = nativeResponse.data;
|
|
436
|
+
this.responseText = JSON.stringify(nativeResponse.data);
|
|
437
|
+
this.responseURL = nativeResponse.url;
|
|
438
|
+
this.readyState = 4;
|
|
439
|
+
this.dispatchEvent(new Event('load'));
|
|
440
|
+
this.dispatchEvent(new Event('loadend'));
|
|
441
|
+
}
|
|
442
|
+
})
|
|
443
|
+
.catch((error) => {
|
|
414
444
|
this.dispatchEvent(new Event('loadstart'));
|
|
415
|
-
this.status =
|
|
416
|
-
this.response =
|
|
417
|
-
this.responseText = JSON.stringify(
|
|
418
|
-
this.responseURL =
|
|
445
|
+
this.status = error.status;
|
|
446
|
+
this.response = error.data;
|
|
447
|
+
this.responseText = JSON.stringify(error.data);
|
|
448
|
+
this.responseURL = error.url;
|
|
419
449
|
this.readyState = 4;
|
|
420
|
-
this.dispatchEvent(new Event('
|
|
450
|
+
this.dispatchEvent(new Event('error'));
|
|
421
451
|
this.dispatchEvent(new Event('loadend'));
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
catch (error) {
|
|
425
455
|
this.dispatchEvent(new Event('loadstart'));
|
|
426
|
-
this.status =
|
|
427
|
-
this.response = error
|
|
428
|
-
this.responseText =
|
|
429
|
-
this.responseURL =
|
|
456
|
+
this.status = 500;
|
|
457
|
+
this.response = error;
|
|
458
|
+
this.responseText = error.toString();
|
|
459
|
+
this.responseURL = this._url;
|
|
430
460
|
this.readyState = 4;
|
|
431
461
|
this.dispatchEvent(new Event('error'));
|
|
432
462
|
this.dispatchEvent(new Event('loadend'));
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
this.dispatchEvent(new Event('loadstart'));
|
|
437
|
-
this.status = 500;
|
|
438
|
-
this.response = error;
|
|
439
|
-
this.responseText = error.toString();
|
|
440
|
-
this.responseURL = this._url;
|
|
441
|
-
this.readyState = 4;
|
|
442
|
-
this.dispatchEvent(new Event('error'));
|
|
443
|
-
this.dispatchEvent(new Event('loadend'));
|
|
444
|
-
}
|
|
445
|
-
};
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
}
|
|
446
466
|
}
|
|
447
467
|
// patch window.console on iOS and store original console fns
|
|
448
468
|
const isIos = getPlatformId(win) === 'ios';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacitor/ios",
|
|
3
|
-
"version": "4.1.1-dev-
|
|
3
|
+
"version": "4.1.1-dev-637db572-20220913T1704.0",
|
|
4
4
|
"description": "Capacitor: Cross-platform apps with JavaScript and the web",
|
|
5
5
|
"homepage": "https://capacitorjs.com",
|
|
6
6
|
"author": "Ionic Team <hi@ionic.io> (https://ionic.io)",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "637db5728bac3b7a3cc3f046347d68e298311f91"
|
|
34
34
|
}
|