@capgo/capacitor-inappbrowser 8.6.15

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.
Files changed (59) hide show
  1. package/CapgoCapacitorInappbrowser.podspec +17 -0
  2. package/LICENSE +373 -0
  3. package/Package.swift +28 -0
  4. package/README.md +1610 -0
  5. package/android/build.gradle +64 -0
  6. package/android/src/main/AndroidManifest.xml +22 -0
  7. package/android/src/main/assets/proxy-bridge.js +586 -0
  8. package/android/src/main/java/ee/forgr/capacitor_inappbrowser/ActiveWebViewSupport.java +10 -0
  9. package/android/src/main/java/ee/forgr/capacitor_inappbrowser/CustomSchemeInterceptSupport.java +51 -0
  10. package/android/src/main/java/ee/forgr/capacitor_inappbrowser/InAppBrowserPlugin.java +1820 -0
  11. package/android/src/main/java/ee/forgr/capacitor_inappbrowser/MobileAppBridgeScript.java +122 -0
  12. package/android/src/main/java/ee/forgr/capacitor_inappbrowser/NativeProxyRule.java +128 -0
  13. package/android/src/main/java/ee/forgr/capacitor_inappbrowser/Options.java +725 -0
  14. package/android/src/main/java/ee/forgr/capacitor_inappbrowser/ProxyBridge.java +93 -0
  15. package/android/src/main/java/ee/forgr/capacitor_inappbrowser/ProxyRequestSupport.java +869 -0
  16. package/android/src/main/java/ee/forgr/capacitor_inappbrowser/ProxyResponseRouting.java +35 -0
  17. package/android/src/main/java/ee/forgr/capacitor_inappbrowser/SafeAreaInsetsSupport.java +28 -0
  18. package/android/src/main/java/ee/forgr/capacitor_inappbrowser/WebViewCallbacks.java +42 -0
  19. package/android/src/main/java/ee/forgr/capacitor_inappbrowser/WebViewDialog.java +6022 -0
  20. package/android/src/main/java/ee/forgr/capacitor_inappbrowser/WebViewPermissionSupport.java +58 -0
  21. package/android/src/main/res/.gitkeep +0 -0
  22. package/android/src/main/res/drawable/arrow_back_disabled.xml +9 -0
  23. package/android/src/main/res/drawable/arrow_back_enabled.xml +9 -0
  24. package/android/src/main/res/drawable/arrow_forward_disabled.xml +9 -0
  25. package/android/src/main/res/drawable/arrow_forward_enabled.xml +9 -0
  26. package/android/src/main/res/drawable/ic_clear_24px.xml +9 -0
  27. package/android/src/main/res/drawable/ic_refresh.xml +9 -0
  28. package/android/src/main/res/drawable/ic_share.xml +10 -0
  29. package/android/src/main/res/layout/activity_browser.xml +32 -0
  30. package/android/src/main/res/layout/bridge_layout_main.xml +15 -0
  31. package/android/src/main/res/layout/content_browser.xml +17 -0
  32. package/android/src/main/res/layout/tool_bar.xml +87 -0
  33. package/android/src/main/res/values/browser_theme.xml +3 -0
  34. package/android/src/main/res/values/colors.xml +5 -0
  35. package/android/src/main/res/values/dimens.xml +3 -0
  36. package/android/src/main/res/values/strings.xml +13 -0
  37. package/android/src/main/res/values/styles.xml +4 -0
  38. package/android/src/main/res/values/themes.xml +27 -0
  39. package/android/src/main/res/xml/file_paths.xml +14 -0
  40. package/dist/docs.json +3200 -0
  41. package/dist/esm/definitions.d.ts +1507 -0
  42. package/dist/esm/definitions.js +40 -0
  43. package/dist/esm/definitions.js.map +1 -0
  44. package/dist/esm/index.d.ts +6 -0
  45. package/dist/esm/index.js +102 -0
  46. package/dist/esm/index.js.map +1 -0
  47. package/dist/esm/web.d.ts +47 -0
  48. package/dist/esm/web.js +120 -0
  49. package/dist/esm/web.js.map +1 -0
  50. package/dist/plugin.cjs.js +270 -0
  51. package/dist/plugin.cjs.js.map +1 -0
  52. package/dist/plugin.js +273 -0
  53. package/dist/plugin.js.map +1 -0
  54. package/ios/Sources/InAppBrowserPlugin/Enums.swift +65 -0
  55. package/ios/Sources/InAppBrowserPlugin/InAppBrowserPlugin.swift +1932 -0
  56. package/ios/Sources/InAppBrowserPlugin/ProxySchemeHandler.swift +1185 -0
  57. package/ios/Sources/InAppBrowserPlugin/WKWebView+SchemeHandling.swift +43 -0
  58. package/ios/Sources/InAppBrowserPlugin/WKWebViewController.swift +3032 -0
  59. package/package.json +139 -0
@@ -0,0 +1,64 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
6
+ androidxBrowserVersion = project.hasProperty('androidxBrowserVersion') ? rootProject.ext.androidxBrowserVersion : '1.9.0'
7
+ }
8
+
9
+ buildscript {
10
+ repositories {
11
+ google()
12
+ mavenCentral()
13
+ }
14
+ dependencies {
15
+ classpath 'com.android.tools.build:gradle:8.13.0'
16
+ }
17
+ }
18
+
19
+ apply plugin: 'com.android.library'
20
+
21
+ android {
22
+ namespace = "ee.forgr.capacitor_inappbrowser"
23
+ compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
24
+ defaultConfig {
25
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
26
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
27
+ versionCode 1
28
+ versionName "1.0"
29
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
30
+ }
31
+ buildTypes {
32
+ release {
33
+ minifyEnabled false
34
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
35
+ }
36
+ }
37
+ lintOptions {
38
+ abortOnError = false
39
+ }
40
+ compileOptions {
41
+ sourceCompatibility JavaVersion.VERSION_21
42
+ targetCompatibility JavaVersion.VERSION_21
43
+ }
44
+ }
45
+
46
+ repositories {
47
+ google()
48
+ mavenCentral()
49
+ }
50
+
51
+
52
+ dependencies {
53
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
54
+ implementation project(':capacitor-android')
55
+ implementation 'com.caverock:androidsvg-aar:1.4'
56
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
57
+ implementation "androidx.window:window:1.5.1"
58
+ testImplementation "junit:junit:$junitVersion"
59
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
60
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
61
+ implementation "androidx.browser:browser:$androidxBrowserVersion"
62
+ implementation 'com.google.android.material:material:1.13.0'
63
+ implementation 'androidx.webkit:webkit:1.15.0'
64
+ }
@@ -0,0 +1,22 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <queries>
3
+ <intent>
4
+ <action android:name="android.intent.action.VIEW" />
5
+ <category android:name="android.intent.category.BROWSABLE" />
6
+ <data android:scheme="http" />
7
+ </intent>
8
+ </queries>
9
+ <uses-permission android:name="android.permission.CAMERA"/>
10
+
11
+ <application>
12
+ <provider
13
+ android:name="androidx.core.content.FileProvider"
14
+ android:authorities="${applicationId}.fileprovider"
15
+ android:exported="false"
16
+ android:grantUriPermissions="true">
17
+ <meta-data
18
+ android:name="android.support.FILE_PROVIDER_PATHS"
19
+ android:resource="@xml/file_paths" />
20
+ </provider>
21
+ </application>
22
+ </manifest>
@@ -0,0 +1,586 @@
1
+ "use strict";
2
+ (() => {
3
+ var __async = (__this, __arguments, generator) => {
4
+ return new Promise((resolve, reject) => {
5
+ var fulfilled = (value) => {
6
+ try {
7
+ step(generator.next(value));
8
+ } catch (e) {
9
+ reject(e);
10
+ }
11
+ };
12
+ var rejected = (value) => {
13
+ try {
14
+ step(generator.throw(value));
15
+ } catch (e) {
16
+ reject(e);
17
+ }
18
+ };
19
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
20
+ step((generator = generator.apply(__this, __arguments)).next());
21
+ });
22
+ };
23
+
24
+ // src/proxy-bridge-support.ts
25
+ function findCapturedHeaderKey(headers, headerName) {
26
+ const normalizedHeaderName = headerName.toLowerCase();
27
+ for (const key of Object.keys(headers)) {
28
+ if (key.toLowerCase() === normalizedHeaderName) {
29
+ return key;
30
+ }
31
+ }
32
+ return null;
33
+ }
34
+ function isNativeProxyErrorResponse(response) {
35
+ return response.status === 599 && response.headers.get("x-capgo-proxy-error") !== null;
36
+ }
37
+ function nativeProxyErrorMessage(response) {
38
+ const nativeErrorHeader = response.headers.get("x-capgo-proxy-error");
39
+ if (!nativeErrorHeader) {
40
+ return "Network request failed";
41
+ }
42
+ const nativeMessage = nativeErrorHeader.trim();
43
+ return nativeMessage || "Network request failed";
44
+ }
45
+ function replaceCapturedHeader(headers, name, value) {
46
+ const existingKey = findCapturedHeaderKey(headers, name);
47
+ if (existingKey && existingKey !== name) {
48
+ delete headers[existingKey];
49
+ }
50
+ headers[name] = value;
51
+ }
52
+ function appendCapturedHeader(headers, name, value) {
53
+ const existingKey = findCapturedHeaderKey(headers, name);
54
+ if (!existingKey) {
55
+ headers[name] = value;
56
+ return;
57
+ }
58
+ headers[existingKey] = headers[existingKey] ? `${headers[existingKey]}, ${value}` : value;
59
+ }
60
+ function inferContentTypeFromBody(body) {
61
+ if (typeof body === "string") {
62
+ return "text/plain;charset=UTF-8";
63
+ }
64
+ if (body instanceof URLSearchParams) {
65
+ return "application/x-www-form-urlencoded;charset=UTF-8";
66
+ }
67
+ if (typeof Blob !== "undefined" && body instanceof Blob) {
68
+ return body.type || null;
69
+ }
70
+ return null;
71
+ }
72
+ function ensureInferredContentType(headers, body) {
73
+ if (findCapturedHeaderKey(headers, "content-type")) {
74
+ return;
75
+ }
76
+ const inferredContentType = inferContentTypeFromBody(body);
77
+ if (inferredContentType) {
78
+ headers["content-type"] = inferredContentType;
79
+ }
80
+ }
81
+ function resolveProxyBridgeUrl(rawUrl, baseUrl) {
82
+ try {
83
+ return new URL(rawUrl, baseUrl).href;
84
+ } catch (_error) {
85
+ return null;
86
+ }
87
+ }
88
+ function shouldProxyBridgeUrl(rawUrl, baseUrl, urlRegex) {
89
+ const resolvedUrl = resolveProxyBridgeUrl(rawUrl, baseUrl);
90
+ if (!resolvedUrl) {
91
+ return false;
92
+ }
93
+ const protocol = new URL(resolvedUrl).protocol.toLowerCase();
94
+ if (protocol !== "http:" && protocol !== "https:") {
95
+ return false;
96
+ }
97
+ return !urlRegex || urlRegex.test(resolvedUrl);
98
+ }
99
+ function getSubmitEventSubmitter(event, submitEventCtor) {
100
+ var _a, _b;
101
+ const resolvedSubmitEventCtor = submitEventCtor != null ? submitEventCtor : typeof SubmitEvent !== "undefined" ? SubmitEvent : void 0;
102
+ if (resolvedSubmitEventCtor && event instanceof resolvedSubmitEventCtor) {
103
+ return (_a = event.submitter) != null ? _a : null;
104
+ }
105
+ if ("submitter" in event) {
106
+ return (_b = event.submitter) != null ? _b : null;
107
+ }
108
+ return null;
109
+ }
110
+ function shouldProxySubmitEvent(defaultPrevented, canProxyTarget) {
111
+ return !defaultPrevented && canProxyTarget;
112
+ }
113
+ function shouldProxySubmitRequest(defaultPrevented, canProxyTarget, rawUrl, baseUrl, urlRegex) {
114
+ return shouldProxySubmitEvent(defaultPrevented, canProxyTarget) && shouldProxyBridgeUrl(rawUrl, baseUrl, urlRegex);
115
+ }
116
+ function consumeProxySubmitReplayBypass(form) {
117
+ if (!form.__capgoSkipNextProxySubmit) {
118
+ return false;
119
+ }
120
+ delete form.__capgoSkipNextProxySubmit;
121
+ return true;
122
+ }
123
+ function replaySubmitAfterProxyFailure(form, originalSubmit, submitter) {
124
+ if (typeof form.requestSubmit === "function") {
125
+ form.__capgoSkipNextProxySubmit = true;
126
+ try {
127
+ if (submitter !== null && submitter !== void 0) {
128
+ form.requestSubmit(submitter);
129
+ } else {
130
+ form.requestSubmit();
131
+ }
132
+ return;
133
+ } catch (_error) {
134
+ delete form.__capgoSkipNextProxySubmit;
135
+ }
136
+ }
137
+ originalSubmit.call(form);
138
+ }
139
+ function captureXhrReplayState(xhr) {
140
+ var _a, _b, _c, _d;
141
+ return {
142
+ responseType: (_a = xhr.responseType) != null ? _a : "",
143
+ timeout: (_b = xhr.timeout) != null ? _b : 0,
144
+ withCredentials: (_c = xhr.withCredentials) != null ? _c : false,
145
+ overrideMimeType: (_d = xhr.__proxyOverrideMimeType) != null ? _d : null
146
+ };
147
+ }
148
+ function restoreXhrReplayState(xhr, state) {
149
+ xhr.responseType = state.responseType;
150
+ xhr.timeout = state.timeout;
151
+ xhr.withCredentials = state.withCredentials;
152
+ xhr.__proxyOverrideMimeType = state.overrideMimeType;
153
+ if (state.overrideMimeType && typeof xhr.overrideMimeType === "function") {
154
+ xhr.overrideMimeType(state.overrideMimeType);
155
+ }
156
+ }
157
+
158
+ // src/proxy-bridge.ts
159
+ (function() {
160
+ const proxyBridge = window.__capgoProxy;
161
+ if (!proxyBridge) {
162
+ return;
163
+ }
164
+ const accessToken = "___CAPGO_PROXY_TOKEN___";
165
+ const proxyRegexSource = "___CAPGO_PROXY_REGEX___";
166
+ let requestCounter = 0;
167
+ let proxyRequestPattern = null;
168
+ if (proxyRegexSource) {
169
+ try {
170
+ proxyRequestPattern = new RegExp(proxyRegexSource);
171
+ } catch (_error) {
172
+ proxyRequestPattern = null;
173
+ }
174
+ }
175
+ function generateRequestId() {
176
+ return "pr_" + Date.now() + "_" + requestCounter++;
177
+ }
178
+ function arrayBufferToBase64(buffer) {
179
+ const bytes = new Uint8Array(buffer);
180
+ let binary = "";
181
+ for (let i = 0; i < bytes.byteLength; i++) {
182
+ binary += String.fromCharCode(bytes[i]);
183
+ }
184
+ return btoa(binary);
185
+ }
186
+ function stringToBase64(value) {
187
+ return btoa(unescape(encodeURIComponent(value)));
188
+ }
189
+ function hasHeader(headers, headerName) {
190
+ const normalizedHeaderName = headerName.toLowerCase();
191
+ return Object.keys(headers).some((key) => key.toLowerCase() === normalizedHeaderName);
192
+ }
193
+ function normalizeMethod(method) {
194
+ return (method || "GET").toUpperCase();
195
+ }
196
+ function normalizeCredentialsMode(mode) {
197
+ if (mode === "omit" || mode === "include") {
198
+ return mode;
199
+ }
200
+ return "same-origin";
201
+ }
202
+ function getDocumentBaseUrl() {
203
+ if (typeof document !== "undefined" && typeof document.baseURI === "string" && document.baseURI) {
204
+ return document.baseURI;
205
+ }
206
+ return window.location.href;
207
+ }
208
+ function resolveUrl(url) {
209
+ if (url && !url.match(/^[a-zA-Z][a-zA-Z0-9+\-.]*:\/\//)) {
210
+ try {
211
+ return new URL(url, getDocumentBaseUrl()).href;
212
+ } catch (_error) {
213
+ return url;
214
+ }
215
+ }
216
+ return url;
217
+ }
218
+ function methodSupportsRequestBody(method) {
219
+ const normalizedMethod = normalizeMethod(method);
220
+ return normalizedMethod !== "GET" && normalizedMethod !== "HEAD";
221
+ }
222
+ function bodyToBase64(body) {
223
+ return __async(this, null, function* () {
224
+ if (body === null || body === void 0) {
225
+ return null;
226
+ }
227
+ if (typeof body === "string") {
228
+ return stringToBase64(body);
229
+ }
230
+ if (body instanceof ArrayBuffer) {
231
+ return arrayBufferToBase64(body);
232
+ }
233
+ if (ArrayBuffer.isView(body)) {
234
+ return arrayBufferToBase64(body.buffer.slice(body.byteOffset, body.byteOffset + body.byteLength));
235
+ }
236
+ if (body instanceof Blob) {
237
+ const buffer = yield body.arrayBuffer();
238
+ return arrayBufferToBase64(buffer);
239
+ }
240
+ if (body instanceof FormData) {
241
+ const buffer = yield new Response(body).arrayBuffer();
242
+ return arrayBufferToBase64(buffer);
243
+ }
244
+ if (body instanceof URLSearchParams) {
245
+ return stringToBase64(body.toString());
246
+ }
247
+ return null;
248
+ });
249
+ }
250
+ function storeInterceptedRequest(url, method, headers, body, credentialsMode) {
251
+ return __async(this, null, function* () {
252
+ const requestId = generateRequestId();
253
+ const normalizedMethod = normalizeMethod(method);
254
+ let normalizedBody = body;
255
+ if (normalizedBody instanceof FormData) {
256
+ const encoded = new Response(normalizedBody);
257
+ const contentType = encoded.headers.get("content-type");
258
+ if (contentType) {
259
+ replaceCapturedHeader(headers, "content-type", contentType);
260
+ }
261
+ normalizedBody = yield encoded.arrayBuffer();
262
+ }
263
+ if (!methodSupportsRequestBody(normalizedMethod)) {
264
+ normalizedBody = null;
265
+ }
266
+ ensureInferredContentType(headers, normalizedBody);
267
+ const base64Body = yield bodyToBase64(normalizedBody);
268
+ if (normalizedBody !== null && normalizedBody !== void 0 && base64Body === null && methodSupportsRequestBody(normalizedMethod)) {
269
+ throw new Error(`[proxy-bridge] Unsupported request body for ${normalizedMethod} proxy replay`);
270
+ }
271
+ proxyBridge.storeRequest(
272
+ accessToken,
273
+ requestId,
274
+ normalizedMethod,
275
+ JSON.stringify(headers),
276
+ base64Body || "",
277
+ normalizeCredentialsMode(credentialsMode)
278
+ );
279
+ return "/_capgo_proxy_?u=" + encodeURIComponent(url) + "&rid=" + requestId;
280
+ });
281
+ }
282
+ function getSubmitterAttribute(submitter, attributeName) {
283
+ if (!(submitter instanceof HTMLElement)) {
284
+ return null;
285
+ }
286
+ return submitter.getAttribute(attributeName);
287
+ }
288
+ function createFormData(form, submitter) {
289
+ if (submitter instanceof HTMLElement) {
290
+ try {
291
+ return new FormData(form, submitter);
292
+ } catch (_error) {
293
+ }
294
+ }
295
+ return new FormData(form);
296
+ }
297
+ function appendFormDataToUrl(url, formData) {
298
+ const resolvedUrl = new URL(url, getDocumentBaseUrl());
299
+ const searchParams = new URLSearchParams(resolvedUrl.search);
300
+ formData.forEach((value, key) => {
301
+ searchParams.append(key, typeof value === "string" ? value : value.name);
302
+ });
303
+ resolvedUrl.search = searchParams.toString();
304
+ return resolvedUrl.toString();
305
+ }
306
+ function formDataToUrlSearchParams(formData) {
307
+ const searchParams = new URLSearchParams();
308
+ formData.forEach((value, key) => {
309
+ searchParams.append(key, typeof value === "string" ? value : value.name);
310
+ });
311
+ return searchParams;
312
+ }
313
+ function formDataToPlainText(formData) {
314
+ const lines = [];
315
+ formData.forEach((value, key) => {
316
+ lines.push(key + "=" + (typeof value === "string" ? value : value.name));
317
+ });
318
+ return lines.join("\r\n");
319
+ }
320
+ function resolveFormMethod(form, submitter) {
321
+ return normalizeMethod(getSubmitterAttribute(submitter, "formmethod") || form.getAttribute("method"));
322
+ }
323
+ function resolveFormAction(form, submitter) {
324
+ return resolveUrl(
325
+ getSubmitterAttribute(submitter, "formaction") || form.getAttribute("action") || getDocumentBaseUrl()
326
+ );
327
+ }
328
+ function resolveFormTarget(form, submitter) {
329
+ return (getSubmitterAttribute(submitter, "formtarget") || form.getAttribute("target") || "").trim();
330
+ }
331
+ function resolveFormEnctype(form, submitter) {
332
+ return (getSubmitterAttribute(submitter, "formenctype") || form.getAttribute("enctype") || "application/x-www-form-urlencoded").toLowerCase();
333
+ }
334
+ function canProxyFormTarget(target) {
335
+ const normalizedTarget = target.toLowerCase();
336
+ return normalizedTarget === "" || normalizedTarget === "_self" || normalizedTarget === "_top" || normalizedTarget === "_parent";
337
+ }
338
+ function navigateFormProxy(proxyUrl, target) {
339
+ const normalizedTarget = target.toLowerCase();
340
+ if (!normalizedTarget || normalizedTarget === "_self") {
341
+ window.location.assign(proxyUrl);
342
+ return;
343
+ }
344
+ if (normalizedTarget === "_top" && window.top) {
345
+ window.top.location.assign(proxyUrl);
346
+ return;
347
+ }
348
+ if (normalizedTarget === "_parent" && window.parent) {
349
+ window.parent.location.assign(proxyUrl);
350
+ return;
351
+ }
352
+ window.location.assign(proxyUrl);
353
+ }
354
+ function proxyFormSubmission(form, submitter) {
355
+ return __async(this, null, function* () {
356
+ const target = resolveFormTarget(form, submitter);
357
+ if (!canProxyFormTarget(target)) {
358
+ return false;
359
+ }
360
+ const method = resolveFormMethod(form, submitter);
361
+ const actionUrl = resolveFormAction(form, submitter);
362
+ const formData = createFormData(form, submitter);
363
+ const headers = {};
364
+ let requestUrl = actionUrl;
365
+ let body = null;
366
+ if (method === "GET" || method === "HEAD") {
367
+ requestUrl = appendFormDataToUrl(actionUrl, formData);
368
+ } else {
369
+ const enctype = resolveFormEnctype(form, submitter);
370
+ if (enctype === "text/plain") {
371
+ headers["content-type"] = "text/plain;charset=UTF-8";
372
+ body = formDataToPlainText(formData);
373
+ } else if (enctype === "multipart/form-data") {
374
+ body = formData;
375
+ } else {
376
+ headers["content-type"] = "application/x-www-form-urlencoded;charset=UTF-8";
377
+ body = formDataToUrlSearchParams(formData);
378
+ }
379
+ }
380
+ if (!shouldProxyBridgeUrl(requestUrl, getDocumentBaseUrl(), proxyRequestPattern)) {
381
+ return false;
382
+ }
383
+ const proxyUrl = yield storeInterceptedRequest(requestUrl, method, headers, body, "include");
384
+ navigateFormProxy(proxyUrl, target);
385
+ return true;
386
+ });
387
+ }
388
+ const originalFetch = window.fetch;
389
+ window.fetch = function(input, init) {
390
+ return __async(this, null, function* () {
391
+ var _a;
392
+ let url;
393
+ let method = "GET";
394
+ const headers = {};
395
+ let inheritedHeaders = false;
396
+ let body = null;
397
+ let credentialsMode = "same-origin";
398
+ let requestCloneError = null;
399
+ if (input instanceof Request) {
400
+ url = input.url;
401
+ method = input.method;
402
+ credentialsMode = normalizeCredentialsMode(input.credentials);
403
+ inheritedHeaders = true;
404
+ input.headers.forEach((value, key) => {
405
+ headers[key] = value;
406
+ });
407
+ try {
408
+ const cloned = input.clone();
409
+ const buffer = yield cloned.arrayBuffer();
410
+ if (buffer.byteLength > 0) {
411
+ body = buffer;
412
+ }
413
+ } catch (error) {
414
+ requestCloneError = error;
415
+ }
416
+ } else {
417
+ url = input instanceof URL ? input.toString() : input;
418
+ }
419
+ url = resolveUrl(url);
420
+ if (init) {
421
+ if (init.method) {
422
+ method = init.method;
423
+ }
424
+ if (init.headers) {
425
+ if (inheritedHeaders) {
426
+ Object.keys(headers).forEach((key) => {
427
+ delete headers[key];
428
+ });
429
+ inheritedHeaders = false;
430
+ }
431
+ const normalized = new Headers(init.headers);
432
+ normalized.forEach((value, key) => {
433
+ headers[key] = value;
434
+ });
435
+ }
436
+ if (init.body !== void 0) {
437
+ body = init.body;
438
+ }
439
+ if (init.credentials) {
440
+ credentialsMode = normalizeCredentialsMode(init.credentials);
441
+ }
442
+ }
443
+ if (requestCloneError != null) {
444
+ return originalFetch.call(window, input, init);
445
+ }
446
+ if (!shouldProxyBridgeUrl(url, getDocumentBaseUrl(), proxyRequestPattern)) {
447
+ return originalFetch.call(window, input, init);
448
+ }
449
+ const signal = (_a = init == null ? void 0 : init.signal) != null ? _a : input instanceof Request ? input.signal : void 0;
450
+ let proxyUrl;
451
+ try {
452
+ proxyUrl = yield storeInterceptedRequest(url, method, headers, body, credentialsMode);
453
+ } catch (_error) {
454
+ return originalFetch.call(window, input, init);
455
+ }
456
+ const proxyResponse = yield originalFetch.call(globalThis, proxyUrl, {
457
+ method: "GET",
458
+ signal
459
+ });
460
+ if (isNativeProxyErrorResponse(proxyResponse)) {
461
+ throw new TypeError(nativeProxyErrorMessage(proxyResponse));
462
+ }
463
+ return proxyResponse;
464
+ });
465
+ };
466
+ const originalXhrOpen = XMLHttpRequest.prototype.open;
467
+ const originalXhrSend = XMLHttpRequest.prototype.send;
468
+ const originalXhrAbort = XMLHttpRequest.prototype.abort;
469
+ const originalXhrSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;
470
+ const originalXhrOverrideMimeType = XMLHttpRequest.prototype.overrideMimeType;
471
+ XMLHttpRequest.prototype.open = function(method, url, ...rest) {
472
+ this.__proxyMethod = method;
473
+ this.__proxyUrl = resolveUrl(url instanceof URL ? url.toString() : url);
474
+ this.__proxyHeaders = {};
475
+ this.__proxyAsync = rest[0] !== false;
476
+ this.__proxyCredentials = this.withCredentials ? "include" : "same-origin";
477
+ this.__proxyUsername = typeof rest[1] === "string" ? rest[1] : null;
478
+ this.__proxyPassword = typeof rest[2] === "string" ? rest[2] : "";
479
+ this.__proxyAborted = false;
480
+ this.__proxyOverrideMimeType = null;
481
+ return originalXhrOpen.apply(this, [method, url, ...rest]);
482
+ };
483
+ XMLHttpRequest.prototype.setRequestHeader = function(name, value) {
484
+ if (this.__proxyHeaders) {
485
+ appendCapturedHeader(this.__proxyHeaders, name, value);
486
+ }
487
+ return originalXhrSetRequestHeader.call(this, name, value);
488
+ };
489
+ XMLHttpRequest.prototype.abort = function() {
490
+ this.__proxyAborted = true;
491
+ return originalXhrAbort.call(this);
492
+ };
493
+ if (typeof originalXhrOverrideMimeType === "function") {
494
+ XMLHttpRequest.prototype.overrideMimeType = function(mimeType) {
495
+ this.__proxyOverrideMimeType = mimeType;
496
+ return originalXhrOverrideMimeType.call(this, mimeType);
497
+ };
498
+ }
499
+ XMLHttpRequest.prototype.send = function(body) {
500
+ const xhr = this;
501
+ const method = xhr.__proxyMethod || "GET";
502
+ const url = xhr.__proxyUrl || "";
503
+ const headers = xhr.__proxyHeaders || {};
504
+ const isAsync = xhr.__proxyAsync !== false;
505
+ const credentialsMode = xhr.withCredentials ? "include" : "same-origin";
506
+ const username = xhr.__proxyUsername;
507
+ const password = xhr.__proxyPassword;
508
+ if (typeof username === "string" && username.length > 0 && !hasHeader(headers, "Authorization")) {
509
+ headers["Authorization"] = "Basic " + stringToBase64(username + ":" + (typeof password === "string" ? password : ""));
510
+ }
511
+ function completeSend(proxyUrl) {
512
+ if (xhr.__proxyAborted) {
513
+ return;
514
+ }
515
+ const replayState = captureXhrReplayState(xhr);
516
+ originalXhrOpen.call(xhr, "GET", proxyUrl, true);
517
+ restoreXhrReplayState(xhr, replayState);
518
+ originalXhrSend.call(xhr, null);
519
+ }
520
+ if (!shouldProxyBridgeUrl(url, getDocumentBaseUrl(), proxyRequestPattern)) {
521
+ originalXhrSend.call(xhr, body != null ? body : null);
522
+ return;
523
+ }
524
+ if (!isAsync) {
525
+ console.warn("[proxy-bridge] Synchronous XMLHttpRequest cannot be proxied; falling back to the original request");
526
+ originalXhrSend.call(xhr, body != null ? body : null);
527
+ return;
528
+ }
529
+ storeInterceptedRequest(url, method, headers, body, credentialsMode).then((proxyUrl) => {
530
+ completeSend(proxyUrl);
531
+ }).catch((_error) => {
532
+ if (xhr.__proxyAborted) {
533
+ return;
534
+ }
535
+ console.error("[proxy-bridge] Failed to encode XMLHttpRequest body");
536
+ originalXhrSend.call(xhr, body != null ? body : null);
537
+ });
538
+ };
539
+ const originalFormSubmit = HTMLFormElement.prototype.submit;
540
+ document.addEventListener("submit", (event) => {
541
+ const form = event.target instanceof HTMLFormElement ? event.target : null;
542
+ if (!form) {
543
+ return;
544
+ }
545
+ if (consumeProxySubmitReplayBypass(form)) {
546
+ return;
547
+ }
548
+ const submitter = getSubmitEventSubmitter(event);
549
+ const target = resolveFormTarget(form, submitter);
550
+ const method = resolveFormMethod(form, submitter);
551
+ let requestUrl = resolveFormAction(form, submitter);
552
+ if (method === "GET" || method === "HEAD") {
553
+ requestUrl = appendFormDataToUrl(requestUrl, createFormData(form, submitter));
554
+ }
555
+ if (!shouldProxySubmitRequest(
556
+ event.defaultPrevented,
557
+ canProxyFormTarget(target),
558
+ requestUrl,
559
+ getDocumentBaseUrl(),
560
+ proxyRequestPattern
561
+ )) {
562
+ return;
563
+ }
564
+ event.preventDefault();
565
+ proxyFormSubmission(form, submitter).then((handled) => {
566
+ if (!handled) {
567
+ replaySubmitAfterProxyFailure(form, originalFormSubmit, submitter);
568
+ }
569
+ }).catch((error) => {
570
+ console.error("[proxy-bridge] Failed to proxy form submission", error);
571
+ replaySubmitAfterProxyFailure(form, originalFormSubmit, submitter);
572
+ });
573
+ });
574
+ HTMLFormElement.prototype.submit = function() {
575
+ const form = this;
576
+ proxyFormSubmission(form).then((handled) => {
577
+ if (!handled) {
578
+ originalFormSubmit.call(form);
579
+ }
580
+ }).catch((_error) => {
581
+ console.error("[proxy-bridge] Failed to proxy programmatic form submission");
582
+ originalFormSubmit.call(form);
583
+ });
584
+ };
585
+ })();
586
+ })();
@@ -0,0 +1,10 @@
1
+ package ee.forgr.capacitor_inappbrowser;
2
+
3
+ final class ActiveWebViewSupport {
4
+
5
+ private ActiveWebViewSupport() {}
6
+
7
+ static boolean shouldActivateNewWebView(boolean isHidden, boolean hasActiveWebView) {
8
+ return !isHidden || !hasActiveWebView;
9
+ }
10
+ }