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