@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
- // fetch patch
295
- window.fetch = async (resource, options) => {
296
- if (resource.toString().startsWith('data:')) {
297
- return win.CapacitorWebFetch(resource, options);
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
- try {
300
- // intercept request & pass to the bridge
301
- const nativeResponse = await cap.nativePromise('CapacitorHttp', 'request', {
302
- url: resource,
303
- method: (options === null || options === void 0 ? void 0 : options.method) ? options.method : undefined,
304
- data: (options === null || options === void 0 ? void 0 : options.body) ? options.body : undefined,
305
- headers: (options === null || options === void 0 ? void 0 : options.headers) ? options.headers : undefined,
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
- // intercept & parse response before returning
308
- const response = new Response(JSON.stringify(nativeResponse.data), {
309
- headers: nativeResponse.headers,
310
- status: nativeResponse.status,
344
+ this.addEventListener('error', function () {
345
+ if (typeof this.onerror === 'function')
346
+ this.onerror();
311
347
  });
312
- return response;
313
- }
314
- catch (error) {
315
- return Promise.reject(error);
316
- }
317
- };
318
- // XHR event listeners
319
- const addEventListeners = function () {
320
- this.addEventListener('abort', function () {
321
- if (typeof this.onabort === 'function')
322
- this.onabort();
323
- });
324
- this.addEventListener('error', function () {
325
- if (typeof this.onerror === 'function')
326
- this.onerror();
327
- });
328
- this.addEventListener('load', function () {
329
- if (typeof this.onload === 'function')
330
- this.onload();
331
- });
332
- this.addEventListener('loadend', function () {
333
- if (typeof this.onloadend === 'function')
334
- this.onloadend();
335
- });
336
- this.addEventListener('loadstart', function () {
337
- if (typeof this.onloadstart === 'function')
338
- this.onloadstart();
339
- });
340
- this.addEventListener('readystatechange', function () {
341
- if (typeof this.onreadystatechange === 'function')
342
- this.onreadystatechange();
343
- });
344
- this.addEventListener('timeout', function () {
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
- set: function (val) {
362
- this._readyState = val;
363
- this.dispatchEvent(new Event('readystatechange'));
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
- response: {
367
- value: '',
368
- writable: true,
369
- },
370
- responseText: {
371
- value: '',
372
- writable: true,
373
- },
374
- responseURL: {
375
- value: '',
376
- writable: true,
377
- },
378
- status: {
379
- value: 0,
380
- writable: true,
381
- },
382
- });
383
- this.readyState = 0;
384
- this.dispatchEvent(new Event('abort'));
385
- this.dispatchEvent(new Event('loadend'));
386
- };
387
- // XHR patch open
388
- window.XMLHttpRequest.prototype.open = function (method, url) {
389
- this.abort();
390
- addEventListeners.call(this);
391
- this._method = method;
392
- this._url = url;
393
- this.readyState = 1;
394
- };
395
- // XHR patch set request header
396
- window.XMLHttpRequest.prototype.setRequestHeader = function (header, value) {
397
- this._headers[header] = value;
398
- };
399
- // XHR patch send
400
- window.XMLHttpRequest.prototype.send = function (body) {
401
- try {
402
- this.readyState = 2;
403
- // intercept request & pass to the bridge
404
- cap
405
- .nativePromise('CapacitorHttp', 'request', {
406
- url: this._url,
407
- method: this._method,
408
- data: body !== null ? body : undefined,
409
- headers: this._headers,
410
- })
411
- .then((nativeResponse) => {
412
- // intercept & parse response before returning
413
- if (this.readyState == 2) {
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 = nativeResponse.status;
416
- this.response = nativeResponse.data;
417
- this.responseText = JSON.stringify(nativeResponse.data);
418
- this.responseURL = nativeResponse.url;
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('load'));
450
+ this.dispatchEvent(new Event('error'));
421
451
  this.dispatchEvent(new Event('loadend'));
422
- }
423
- })
424
- .catch((error) => {
452
+ });
453
+ }
454
+ catch (error) {
425
455
  this.dispatchEvent(new Event('loadstart'));
426
- this.status = error.status;
427
- this.response = error.data;
428
- this.responseText = JSON.stringify(error.data);
429
- this.responseURL = error.url;
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
- catch (error) {
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-7e3589f9.0",
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": "7e3589f9bb4673b595f2718e444e2bd07c7749e1"
33
+ "gitHead": "637db5728bac3b7a3cc3f046347d68e298311f91"
34
34
  }