@capgo/capacitor-inappbrowser 8.23.0 → 8.24.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.
- package/README.md +82 -80
- package/dist/docs.json +17 -1
- package/dist/esm/definitions.d.ts +50 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.js +6 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +39 -11
- package/dist/esm/web.js +324 -64
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +407 -152
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +407 -152
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/InAppBrowserPlugin/InAppBrowserPlugin.swift +1 -1
- package/package.json +2 -2
package/dist/plugin.js
CHANGED
|
@@ -158,6 +158,408 @@ var capacitorInAppBrowser = (function (exports, core) {
|
|
|
158
158
|
return resolution.url;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
const HTML_ATTRIBUTE_ESCAPES = { '&': '&', '"': '"', '<': '<', '>': '>' };
|
|
162
|
+
const escapeHtmlAttribute = (value) => value.replace(/[&"<>]/g, (c) => HTML_ATTRIBUTE_ESCAPES[c]);
|
|
163
|
+
const OPENING_HEAD_TAG = /<head(?:\s[^>]*)?>/i;
|
|
164
|
+
const NATIVE_BRIDGE_SCRIPT = "(function(){window.addEventListener('message',function(e){if(e.source===window.parent){window.dispatchEvent(new CustomEvent('messageFromNative',{detail:e.data}));}});})();";
|
|
165
|
+
const formatDoctype = (doctype) => {
|
|
166
|
+
if (!doctype) {
|
|
167
|
+
return '';
|
|
168
|
+
}
|
|
169
|
+
if (doctype.publicId) {
|
|
170
|
+
const system = doctype.systemId ? ` "${doctype.systemId}"` : '';
|
|
171
|
+
return `<!DOCTYPE ${doctype.name} PUBLIC "${doctype.publicId}"${system}>`;
|
|
172
|
+
}
|
|
173
|
+
if (doctype.systemId) {
|
|
174
|
+
return `<!DOCTYPE ${doctype.name} SYSTEM "${doctype.systemId}">`;
|
|
175
|
+
}
|
|
176
|
+
return `<!DOCTYPE ${doctype.name}>`;
|
|
177
|
+
};
|
|
178
|
+
const serializeParsedHtml = (doc) => formatDoctype(doc.doctype) + doc.documentElement.outerHTML;
|
|
179
|
+
const TRUSTED_TYPES_POLICY_NAME = 'capgo-inappbrowser';
|
|
180
|
+
const TRUSTED_TYPES_POLICY_BLOCKED_MESSAGE = "InAppBrowser could not create the Trusted Types policy 'capgo-inappbrowser'. " +
|
|
181
|
+
'Add capgo-inappbrowser to the host app Content-Security-Policy trusted-types directive.';
|
|
182
|
+
let trustedHtmlPolicy;
|
|
183
|
+
const getTrustedHtmlPolicy = () => {
|
|
184
|
+
var _a;
|
|
185
|
+
if (trustedHtmlPolicy !== undefined) {
|
|
186
|
+
return trustedHtmlPolicy;
|
|
187
|
+
}
|
|
188
|
+
const trustedTypes = (_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.trustedTypes;
|
|
189
|
+
if (!trustedTypes) {
|
|
190
|
+
trustedHtmlPolicy = null;
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
trustedHtmlPolicy = trustedTypes.createPolicy(TRUSTED_TYPES_POLICY_NAME, {
|
|
195
|
+
createHTML: (value) => value,
|
|
196
|
+
});
|
|
197
|
+
return trustedHtmlPolicy;
|
|
198
|
+
}
|
|
199
|
+
catch (_b) {
|
|
200
|
+
throw new Error(TRUSTED_TYPES_POLICY_BLOCKED_MESSAGE);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
const createTrustedHtml = (html) => {
|
|
204
|
+
const policy = getTrustedHtmlPolicy();
|
|
205
|
+
return policy ? policy.createHTML(html) : html;
|
|
206
|
+
};
|
|
207
|
+
const trustedHtmlToString = (html) => (typeof html === 'string' ? html : String(html));
|
|
208
|
+
const injectNativeBridge = (html) => {
|
|
209
|
+
if (typeof DOMParser !== 'undefined') {
|
|
210
|
+
const doc = new DOMParser().parseFromString(createTrustedHtml(html), 'text/html');
|
|
211
|
+
const script = doc.createElement('script');
|
|
212
|
+
script.textContent = NATIVE_BRIDGE_SCRIPT;
|
|
213
|
+
if (doc.body) {
|
|
214
|
+
doc.body.appendChild(script);
|
|
215
|
+
return serializeParsedHtml(doc);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return `${html}<script>${NATIVE_BRIDGE_SCRIPT}</script>`;
|
|
219
|
+
};
|
|
220
|
+
/** Whether a webview message origin may replace the postMessage target (full origin string). */
|
|
221
|
+
function mayAdoptPostMessageOrigin(openedUrl, messageOrigin) {
|
|
222
|
+
try {
|
|
223
|
+
const opened = new URL(openedUrl);
|
|
224
|
+
const incoming = new URL(messageOrigin);
|
|
225
|
+
if (opened.protocol !== incoming.protocol) {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
if (opened.port !== incoming.port) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
if (opened.origin === incoming.origin) {
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
const openedHost = opened.hostname;
|
|
235
|
+
const incomingHost = incoming.hostname;
|
|
236
|
+
return incomingHost === openedHost || incomingHost.endsWith(`.${openedHost}`);
|
|
237
|
+
}
|
|
238
|
+
catch (_a) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Wraps fetched HTML in a sandboxed iframe (opaque origin, no allow-same-origin) so the remote page
|
|
244
|
+
* cannot read the app's storage or DOM even though the wrapper is a Blob created by the app origin.
|
|
245
|
+
* A <base href> pointing at the final response URL keeps relative URLs resolving against the target.
|
|
246
|
+
* The wrapper relays messages from the app (its opener) into the sandboxed frame.
|
|
247
|
+
*/
|
|
248
|
+
const buildIsolatedDocument = (html, baseHref) => {
|
|
249
|
+
const baseTag = `<base href="${escapeHtmlAttribute(baseHref)}">`;
|
|
250
|
+
let inner = OPENING_HEAD_TAG.test(html)
|
|
251
|
+
? html.replace(OPENING_HEAD_TAG, (tag) => `${tag}${baseTag}`)
|
|
252
|
+
: `${baseTag}${html}`;
|
|
253
|
+
inner = injectNativeBridge(inner);
|
|
254
|
+
const srcdoc = trustedHtmlToString(createTrustedHtml(inner));
|
|
255
|
+
const sandbox = 'allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-top-navigation-by-user-activation';
|
|
256
|
+
const relay = "(function(){var f=document.getElementById('capgo-iab-frame');" +
|
|
257
|
+
"window.addEventListener('message',function(e){if(e.source===window.opener&&f&&f.contentWindow){f.contentWindow.postMessage(e.data,'*');}});})();";
|
|
258
|
+
return ('<!doctype html><html><head><meta charset="utf-8">' +
|
|
259
|
+
'<style>html,body,iframe{margin:0;padding:0;border:0;width:100%;height:100%;display:block}</style></head>' +
|
|
260
|
+
`<body><iframe id="capgo-iab-frame" sandbox="${sandbox}" referrerpolicy="no-referrer" srcdoc="${escapeHtmlAttribute(srcdoc)}"></iframe>` +
|
|
261
|
+
`<script>${relay}</script></body></html>`);
|
|
262
|
+
};
|
|
263
|
+
class InAppBrowserWeb extends core.WebPlugin {
|
|
264
|
+
constructor() {
|
|
265
|
+
super();
|
|
266
|
+
this.webViews = new Map();
|
|
267
|
+
this.webViewCounter = 0;
|
|
268
|
+
this.handleWindowMessage = (event) => {
|
|
269
|
+
const match = Array.from(this.webViews.entries()).find(([, entry]) => this.isFromWebView(entry, event.source));
|
|
270
|
+
if (!match) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const [id, entry] = match;
|
|
274
|
+
if (entry.window === event.source &&
|
|
275
|
+
event.origin &&
|
|
276
|
+
event.origin !== 'null' &&
|
|
277
|
+
mayAdoptPostMessageOrigin(entry.url, event.origin)) {
|
|
278
|
+
entry.origin = event.origin;
|
|
279
|
+
}
|
|
280
|
+
let data = event.data;
|
|
281
|
+
if (typeof data === 'string') {
|
|
282
|
+
try {
|
|
283
|
+
data = JSON.parse(data);
|
|
284
|
+
}
|
|
285
|
+
catch (_a) {
|
|
286
|
+
this.notifyListeners('messageFromWebview', { id, rawMessage: event.data });
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (data && typeof data === 'object' && !Array.isArray(data)) {
|
|
291
|
+
this.notifyListeners('messageFromWebview', Object.assign(Object.assign({}, data), { id }));
|
|
292
|
+
}
|
|
293
|
+
else if (typeof event.data === 'string') {
|
|
294
|
+
this.notifyListeners('messageFromWebview', { id, rawMessage: event.data });
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
if (globalThis.window !== undefined) {
|
|
298
|
+
globalThis.window.addEventListener('message', this.handleWindowMessage);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
isFromWebView(entry, source) {
|
|
302
|
+
if (!source) {
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
if (entry.window === source) {
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
if (!entry.objectUrl) {
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
try {
|
|
312
|
+
const frame = entry.window.document.getElementById('capgo-iab-frame');
|
|
313
|
+
return (frame === null || frame === void 0 ? void 0 : frame.contentWindow) === source;
|
|
314
|
+
}
|
|
315
|
+
catch (_a) {
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
watchClosed(id) {
|
|
320
|
+
const entry = this.webViews.get(id);
|
|
321
|
+
if (!(entry === null || entry === void 0 ? void 0 : entry.window.closed)) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
globalThis.clearInterval(entry.timer);
|
|
325
|
+
if (entry.objectUrl) {
|
|
326
|
+
URL.revokeObjectURL(entry.objectUrl);
|
|
327
|
+
}
|
|
328
|
+
this.webViews.delete(id);
|
|
329
|
+
this.notifyListeners('closeEvent', { id, url: entry.url });
|
|
330
|
+
}
|
|
331
|
+
resolveWebViewEntry(id) {
|
|
332
|
+
if (id) {
|
|
333
|
+
const entry = this.webViews.get(id);
|
|
334
|
+
if (entry && !entry.window.closed) {
|
|
335
|
+
return { id, entry };
|
|
336
|
+
}
|
|
337
|
+
return undefined;
|
|
338
|
+
}
|
|
339
|
+
const match = Array.from(this.webViews.entries())
|
|
340
|
+
.reverse()
|
|
341
|
+
.find(([, entry]) => !entry.window.closed);
|
|
342
|
+
if (!match) {
|
|
343
|
+
return undefined;
|
|
344
|
+
}
|
|
345
|
+
return { id: match[0], entry: match[1] };
|
|
346
|
+
}
|
|
347
|
+
resolveTargetOrigin(url) {
|
|
348
|
+
var _a, _b;
|
|
349
|
+
try {
|
|
350
|
+
return new URL(url).origin;
|
|
351
|
+
}
|
|
352
|
+
catch (_c) {
|
|
353
|
+
return (_b = (_a = globalThis.location) === null || _a === void 0 ? void 0 : _a.origin) !== null && _b !== void 0 ? _b : 'null';
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
hasHeaders(headers) {
|
|
357
|
+
return headers != null && Object.keys(headers).length > 0;
|
|
358
|
+
}
|
|
359
|
+
navigateOpenedWindow(id, win, url, headers) {
|
|
360
|
+
if (!this.hasHeaders(headers)) {
|
|
361
|
+
win.location.href = url;
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
void (async () => {
|
|
365
|
+
var _a, _b;
|
|
366
|
+
try {
|
|
367
|
+
const response = await fetch(url, { headers });
|
|
368
|
+
if (!response.ok) {
|
|
369
|
+
throw new Error(`Request failed with status ${response.status}`);
|
|
370
|
+
}
|
|
371
|
+
const html = await response.text();
|
|
372
|
+
const parsed = new URL(response.url || url, (_b = (_a = globalThis.location) === null || _a === void 0 ? void 0 : _a.href) !== null && _b !== void 0 ? _b : 'https://localhost/');
|
|
373
|
+
const baseHref = `${parsed.origin}${parsed.pathname}${parsed.search}`;
|
|
374
|
+
const blob = new Blob([buildIsolatedDocument(html, baseHref)], { type: 'text/html;charset=utf-8' });
|
|
375
|
+
const objectUrl = URL.createObjectURL(blob);
|
|
376
|
+
const entry = this.webViews.get(id);
|
|
377
|
+
if (!entry || win.closed) {
|
|
378
|
+
URL.revokeObjectURL(objectUrl);
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
entry.objectUrl = objectUrl;
|
|
382
|
+
win.location.href = objectUrl;
|
|
383
|
+
}
|
|
384
|
+
catch (error) {
|
|
385
|
+
console.error('[InAppBrowser] Failed to load web view with headers', error);
|
|
386
|
+
win.close();
|
|
387
|
+
this.watchClosed(id);
|
|
388
|
+
}
|
|
389
|
+
})();
|
|
390
|
+
}
|
|
391
|
+
clearAllCookies() {
|
|
392
|
+
console.log('clearAllCookies');
|
|
393
|
+
return Promise.resolve();
|
|
394
|
+
}
|
|
395
|
+
clearCache() {
|
|
396
|
+
console.log('clearCache');
|
|
397
|
+
return Promise.resolve();
|
|
398
|
+
}
|
|
399
|
+
clearAllBrowsingData() {
|
|
400
|
+
console.log('clearAllBrowsingData');
|
|
401
|
+
return Promise.resolve();
|
|
402
|
+
}
|
|
403
|
+
open(options) {
|
|
404
|
+
const opened = globalThis.open('', '_blank');
|
|
405
|
+
if (!opened) {
|
|
406
|
+
return Promise.reject(new Error('Popup blocked'));
|
|
407
|
+
}
|
|
408
|
+
opened.opener = null;
|
|
409
|
+
opened.location.href = options.url;
|
|
410
|
+
return Promise.resolve();
|
|
411
|
+
}
|
|
412
|
+
clearCookies(options) {
|
|
413
|
+
console.log('cleanCookies', options);
|
|
414
|
+
return Promise.resolve();
|
|
415
|
+
}
|
|
416
|
+
getCookies(options) {
|
|
417
|
+
return Promise.resolve(options);
|
|
418
|
+
}
|
|
419
|
+
openWebView(options) {
|
|
420
|
+
var _a, _b, _c;
|
|
421
|
+
if (options.fullscreen) {
|
|
422
|
+
return Promise.reject(this.unimplemented('Fullscreen is only supported by native openWebView presentations.'));
|
|
423
|
+
}
|
|
424
|
+
const { popup = false, width, height } = (_a = options.web) !== null && _a !== void 0 ? _a : {};
|
|
425
|
+
const features = popup
|
|
426
|
+
? ['popup=yes', width ? `width=${width}` : '', height ? `height=${height}` : ''].filter(Boolean).join(',')
|
|
427
|
+
: '';
|
|
428
|
+
const opened = globalThis.open('', '_blank', features);
|
|
429
|
+
if (!opened) {
|
|
430
|
+
return Promise.reject(new Error('Popup blocked'));
|
|
431
|
+
}
|
|
432
|
+
const id = `web-${++this.webViewCounter}`;
|
|
433
|
+
const timer = globalThis.setInterval(() => this.watchClosed(id), 500);
|
|
434
|
+
// Header loads render inside an app-origin wrapper document, so messages target the app origin there.
|
|
435
|
+
const origin = this.hasHeaders(options.headers)
|
|
436
|
+
? ((_c = (_b = globalThis.location) === null || _b === void 0 ? void 0 : _b.origin) !== null && _c !== void 0 ? _c : 'null')
|
|
437
|
+
: this.resolveTargetOrigin(options.url);
|
|
438
|
+
this.webViews.set(id, { window: opened, url: options.url, timer, origin });
|
|
439
|
+
this.navigateOpenedWindow(id, opened, options.url, options.headers);
|
|
440
|
+
return Promise.resolve({ id });
|
|
441
|
+
}
|
|
442
|
+
executeScript({ code }) {
|
|
443
|
+
console.log('code', code);
|
|
444
|
+
return Promise.resolve(code);
|
|
445
|
+
}
|
|
446
|
+
close(options) {
|
|
447
|
+
const resolved = this.resolveWebViewEntry(options === null || options === void 0 ? void 0 : options.id);
|
|
448
|
+
if (!resolved) {
|
|
449
|
+
return Promise.resolve();
|
|
450
|
+
}
|
|
451
|
+
resolved.entry.window.close();
|
|
452
|
+
this.watchClosed(resolved.id);
|
|
453
|
+
return Promise.resolve();
|
|
454
|
+
}
|
|
455
|
+
hide(_options) {
|
|
456
|
+
console.log('hide', _options);
|
|
457
|
+
return Promise.resolve();
|
|
458
|
+
}
|
|
459
|
+
show(_options) {
|
|
460
|
+
console.log('show', _options);
|
|
461
|
+
return Promise.resolve();
|
|
462
|
+
}
|
|
463
|
+
sendToBack(_options) {
|
|
464
|
+
console.log('sendToBack not supported on web', _options);
|
|
465
|
+
return Promise.resolve();
|
|
466
|
+
}
|
|
467
|
+
bringToFront(_options) {
|
|
468
|
+
console.log('bringToFront not supported on web', _options);
|
|
469
|
+
return Promise.resolve();
|
|
470
|
+
}
|
|
471
|
+
dispatchInputEvent(_options) {
|
|
472
|
+
console.log('dispatchInputEvent not supported on web', _options);
|
|
473
|
+
return Promise.resolve();
|
|
474
|
+
}
|
|
475
|
+
setUrl(options) {
|
|
476
|
+
console.log('setUrl', options.url);
|
|
477
|
+
return Promise.resolve();
|
|
478
|
+
}
|
|
479
|
+
reload(options) {
|
|
480
|
+
console.log('reload', options);
|
|
481
|
+
return Promise.resolve();
|
|
482
|
+
}
|
|
483
|
+
postMessage(options) {
|
|
484
|
+
const resolved = this.resolveWebViewEntry(options.id);
|
|
485
|
+
if (resolved) {
|
|
486
|
+
resolved.entry.window.postMessage(options.detail, resolved.entry.origin);
|
|
487
|
+
}
|
|
488
|
+
return Promise.resolve();
|
|
489
|
+
}
|
|
490
|
+
takeScreenshot(_options) {
|
|
491
|
+
console.log('takeScreenshot not supported on web', _options);
|
|
492
|
+
return Promise.reject(this.unimplemented('Screenshots are not supported on web.'));
|
|
493
|
+
}
|
|
494
|
+
goBack() {
|
|
495
|
+
console.log('goBack');
|
|
496
|
+
return Promise.resolve();
|
|
497
|
+
}
|
|
498
|
+
getPluginVersion() {
|
|
499
|
+
return Promise.resolve({ version: 'web' });
|
|
500
|
+
}
|
|
501
|
+
updateDimensions(_options) {
|
|
502
|
+
console.log('updateDimensions', _options);
|
|
503
|
+
return Promise.resolve();
|
|
504
|
+
}
|
|
505
|
+
handleProxyRequest(options) {
|
|
506
|
+
console.log('handleProxyRequest not supported on web', options);
|
|
507
|
+
return Promise.resolve();
|
|
508
|
+
}
|
|
509
|
+
setEnabledSafeTopMargin(_options) {
|
|
510
|
+
console.log('setEnabledSafeTopMargin not supported on web', _options);
|
|
511
|
+
return Promise.resolve();
|
|
512
|
+
}
|
|
513
|
+
setFullscreen(options) {
|
|
514
|
+
console.log('setFullscreen not supported on web', options);
|
|
515
|
+
return Promise.reject(this.unimplemented('Fullscreen is only supported by native openWebView presentations.'));
|
|
516
|
+
}
|
|
517
|
+
getFullscreen(_options) {
|
|
518
|
+
console.log('getFullscreen not supported on web', _options);
|
|
519
|
+
return Promise.reject(this.unimplemented('Fullscreen is only supported by native openWebView presentations.'));
|
|
520
|
+
}
|
|
521
|
+
setEnabledSafeBottomMargin(_options) {
|
|
522
|
+
console.log('setEnabledSafeBottomMargin not supported on web', _options);
|
|
523
|
+
return Promise.resolve();
|
|
524
|
+
}
|
|
525
|
+
async openSecureWindow(options) {
|
|
526
|
+
const w = 600;
|
|
527
|
+
const h = 550;
|
|
528
|
+
const settings = [
|
|
529
|
+
['width', w],
|
|
530
|
+
['height', h],
|
|
531
|
+
['left', screen.width / 2 - w / 2],
|
|
532
|
+
['top', screen.height / 2 - h / 2],
|
|
533
|
+
]
|
|
534
|
+
.map((x) => x.join('='))
|
|
535
|
+
.join(',');
|
|
536
|
+
const popup = globalThis.open(options.authEndpoint, 'Authorization', settings);
|
|
537
|
+
if (!popup) {
|
|
538
|
+
throw new Error('Failed to open secure window');
|
|
539
|
+
}
|
|
540
|
+
if (typeof popup.focus === 'function') {
|
|
541
|
+
popup.focus();
|
|
542
|
+
}
|
|
543
|
+
return new Promise((resolve, reject) => {
|
|
544
|
+
const bc = new BroadcastChannel(options.broadcastChannelName || 'oauth-channel');
|
|
545
|
+
bc.addEventListener('message', (event) => {
|
|
546
|
+
if (event.data.startsWith(options.redirectUri)) {
|
|
547
|
+
bc.close();
|
|
548
|
+
resolve({ redirectedUri: event.data });
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
bc.close();
|
|
552
|
+
reject(new Error('Redirect URI does not match, expected ' + options.redirectUri + ' but got ' + event.data));
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
setTimeout(() => {
|
|
556
|
+
bc.close();
|
|
557
|
+
reject(new Error('The sign-in flow timed out'));
|
|
558
|
+
}, 5 * 60000);
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
161
563
|
exports.BackgroundColor = void 0;
|
|
162
564
|
(function (BackgroundColor) {
|
|
163
565
|
BackgroundColor["WHITE"] = "white";
|
|
@@ -236,8 +638,12 @@ var capacitorInAppBrowser = (function (exports, core) {
|
|
|
236
638
|
'Ensure @capgo/capacitor-inappbrowser native code is installed.');
|
|
237
639
|
return CAPGO_PLUGIN_NAME;
|
|
238
640
|
}
|
|
641
|
+
let webImplementation;
|
|
239
642
|
const inAppBrowserImplementations = {
|
|
240
|
-
|
|
643
|
+
// Imported statically so the first openWebView() reaches window.open without awaiting a chunk load,
|
|
644
|
+
// which can outlast the browser's user-activation window and get the popup blocked.
|
|
645
|
+
// Memoized so concurrent first calls share one instance (one id counter and window map).
|
|
646
|
+
web: () => (webImplementation !== null && webImplementation !== void 0 ? webImplementation : (webImplementation = new InAppBrowserWeb())),
|
|
241
647
|
};
|
|
242
648
|
function assertValidBundledAssetPath(url) {
|
|
243
649
|
if (isRelativeBundledPath(url) && containsPathTraversal(url)) {
|
|
@@ -379,157 +785,6 @@ var capacitorInAppBrowser = (function (exports, core) {
|
|
|
379
785
|
});
|
|
380
786
|
};
|
|
381
787
|
|
|
382
|
-
class InAppBrowserWeb extends core.WebPlugin {
|
|
383
|
-
clearAllCookies() {
|
|
384
|
-
console.log('clearAllCookies');
|
|
385
|
-
return Promise.resolve();
|
|
386
|
-
}
|
|
387
|
-
clearCache() {
|
|
388
|
-
console.log('clearCache');
|
|
389
|
-
return Promise.resolve();
|
|
390
|
-
}
|
|
391
|
-
clearAllBrowsingData() {
|
|
392
|
-
console.log('clearAllBrowsingData');
|
|
393
|
-
return Promise.resolve();
|
|
394
|
-
}
|
|
395
|
-
async open(options) {
|
|
396
|
-
console.log('open', options);
|
|
397
|
-
return options;
|
|
398
|
-
}
|
|
399
|
-
async clearCookies(options) {
|
|
400
|
-
console.log('cleanCookies', options);
|
|
401
|
-
return;
|
|
402
|
-
}
|
|
403
|
-
async getCookies(options) {
|
|
404
|
-
// Web implementation to get cookies
|
|
405
|
-
return options;
|
|
406
|
-
}
|
|
407
|
-
async openWebView(options) {
|
|
408
|
-
if (options.fullscreen) {
|
|
409
|
-
throw this.unimplemented('Fullscreen is only supported by native openWebView presentations.');
|
|
410
|
-
}
|
|
411
|
-
console.log('openWebView', options);
|
|
412
|
-
return options;
|
|
413
|
-
}
|
|
414
|
-
async executeScript({ code }) {
|
|
415
|
-
console.log('code', code);
|
|
416
|
-
return code;
|
|
417
|
-
}
|
|
418
|
-
async close(options) {
|
|
419
|
-
console.log('close', options);
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
async hide(options) {
|
|
423
|
-
console.log('hide', options);
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
|
-
async show(options) {
|
|
427
|
-
console.log('show', options);
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
async sendToBack(options) {
|
|
431
|
-
console.log('sendToBack not supported on web', options);
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
async bringToFront(options) {
|
|
435
|
-
console.log('bringToFront not supported on web', options);
|
|
436
|
-
return;
|
|
437
|
-
}
|
|
438
|
-
async dispatchInputEvent(options) {
|
|
439
|
-
console.log('dispatchInputEvent not supported on web', options);
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
async setUrl(options) {
|
|
443
|
-
console.log('setUrl', options.url);
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
async reload(options) {
|
|
447
|
-
console.log('reload', options);
|
|
448
|
-
return;
|
|
449
|
-
}
|
|
450
|
-
async postMessage(options) {
|
|
451
|
-
console.log('postMessage', options);
|
|
452
|
-
return options;
|
|
453
|
-
}
|
|
454
|
-
async takeScreenshot(options) {
|
|
455
|
-
console.log('takeScreenshot not supported on web', options);
|
|
456
|
-
throw this.unimplemented('Screenshots are not supported on web.');
|
|
457
|
-
}
|
|
458
|
-
async goBack() {
|
|
459
|
-
console.log('goBack');
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
async getPluginVersion() {
|
|
463
|
-
return { version: 'web' };
|
|
464
|
-
}
|
|
465
|
-
async updateDimensions(options) {
|
|
466
|
-
console.log('updateDimensions', options);
|
|
467
|
-
// Web platform doesn't support dimension control
|
|
468
|
-
return;
|
|
469
|
-
}
|
|
470
|
-
async handleProxyRequest(options) {
|
|
471
|
-
console.log('handleProxyRequest not supported on web', options);
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
async setEnabledSafeTopMargin(options) {
|
|
475
|
-
console.log('setEnabledSafeTopMargin not supported on web', options);
|
|
476
|
-
return;
|
|
477
|
-
}
|
|
478
|
-
async setFullscreen(options) {
|
|
479
|
-
console.log('setFullscreen not supported on web', options);
|
|
480
|
-
throw this.unimplemented('Fullscreen is only supported by native openWebView presentations.');
|
|
481
|
-
}
|
|
482
|
-
async getFullscreen(options) {
|
|
483
|
-
console.log('getFullscreen not supported on web', options);
|
|
484
|
-
throw this.unimplemented('Fullscreen is only supported by native openWebView presentations.');
|
|
485
|
-
}
|
|
486
|
-
async setEnabledSafeBottomMargin(options) {
|
|
487
|
-
console.log('setEnabledSafeBottomMargin not supported on web', options);
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
async openSecureWindow(options) {
|
|
491
|
-
const w = 600;
|
|
492
|
-
const h = 550;
|
|
493
|
-
const settings = [
|
|
494
|
-
['width', w],
|
|
495
|
-
['height', h],
|
|
496
|
-
['left', screen.width / 2 - w / 2],
|
|
497
|
-
['top', screen.height / 2 - h / 2],
|
|
498
|
-
]
|
|
499
|
-
.map((x) => x.join('='))
|
|
500
|
-
.join(',');
|
|
501
|
-
const popup = window.open(options.authEndpoint, 'Authorization', settings);
|
|
502
|
-
if (!popup) {
|
|
503
|
-
throw new Error('Failed to open secure window');
|
|
504
|
-
}
|
|
505
|
-
if (typeof popup.focus === 'function') {
|
|
506
|
-
popup.focus();
|
|
507
|
-
}
|
|
508
|
-
return new Promise((resolve, reject) => {
|
|
509
|
-
const bc = new BroadcastChannel(options.broadcastChannelName || 'oauth-channel');
|
|
510
|
-
bc.addEventListener('message', (event) => {
|
|
511
|
-
if (event.data.startsWith(options.redirectUri)) {
|
|
512
|
-
bc.close();
|
|
513
|
-
resolve({ redirectedUri: event.data });
|
|
514
|
-
}
|
|
515
|
-
else {
|
|
516
|
-
bc.close();
|
|
517
|
-
reject(new Error('Redirect URI does not match, expected ' + options.redirectUri + ' but got ' + event.data));
|
|
518
|
-
}
|
|
519
|
-
});
|
|
520
|
-
setTimeout(() => {
|
|
521
|
-
bc.close();
|
|
522
|
-
reject(new Error('The sign-in flow timed out'));
|
|
523
|
-
}, 5 * 60000);
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
var web = /*#__PURE__*/Object.freeze({
|
|
529
|
-
__proto__: null,
|
|
530
|
-
InAppBrowserWeb: InAppBrowserWeb
|
|
531
|
-
});
|
|
532
|
-
|
|
533
788
|
exports.InAppBrowser = InAppBrowser;
|
|
534
789
|
exports.addProxyHandler = addProxyHandler;
|
|
535
790
|
|