@capgo/inappbrowser 7.10.8 → 7.10.9

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.
@@ -1119,10 +1119,10 @@ public class WebViewDialog extends Dialog {
1119
1119
  JSONObject jsonObject = new JSONObject();
1120
1120
  jsonObject.put("detail", detail);
1121
1121
  String jsonDetail = jsonObject.toString();
1122
- String script =
1123
- "window.dispatchEvent(new CustomEvent('messageFromNative', " +
1124
- jsonDetail +
1125
- "));";
1122
+ String script = String.format(
1123
+ "window.dispatchEvent(new CustomEvent('messageFromNative', %s));",
1124
+ jsonDetail
1125
+ );
1126
1126
  _webView.post(() -> {
1127
1127
  if (_webView != null) {
1128
1128
  _webView.evaluateJavascript(script, null);
@@ -1148,56 +1148,58 @@ public class WebViewDialog extends Dialog {
1148
1148
 
1149
1149
  try {
1150
1150
  String script =
1151
- "(function() {" +
1152
- " if (window.AndroidInterface) {" +
1153
- " // Create mobileApp object for backward compatibility" +
1154
- " if (!window.mobileApp) {" +
1155
- " window.mobileApp = {" +
1156
- " postMessage: function(message) {" +
1157
- " try {" +
1158
- " var msg = typeof message === 'string' ? message : JSON.stringify(message);" +
1159
- " window.AndroidInterface.postMessage(msg);" +
1160
- " } catch(e) {" +
1161
- " console.error('Error in mobileApp.postMessage:', e);" +
1162
- " }" +
1163
- " }," +
1164
- " close: function() {" +
1165
- " try {" +
1166
- " window.AndroidInterface.close();" +
1167
- " } catch(e) {" +
1168
- " console.error('Error in mobileApp.close:', e);" +
1169
- " }" +
1170
- " }" +
1171
- " };" +
1172
- " }" +
1173
- " // Also provide direct window methods for convenience" +
1174
- " window.postMessage = function(data) {" +
1175
- " try {" +
1176
- " var message = typeof data === 'string' ? data : JSON.stringify(data);" +
1177
- " window.AndroidInterface.postMessage(message);" +
1178
- " } catch(e) {" +
1179
- " console.error('Error in postMessage:', e);" +
1180
- " }" +
1181
- " };" +
1182
- " window.close = function() {" +
1183
- " try {" +
1184
- " window.AndroidInterface.close();" +
1185
- " } catch(e) {" +
1186
- " console.error('Error in close:', e);" +
1187
- " }" +
1188
- " };" +
1189
- " }" +
1190
- " // Override window.print function to use our PrintInterface" +
1191
- " if (window.PrintInterface) {" +
1192
- " window.print = function() {" +
1193
- " try {" +
1194
- " window.PrintInterface.print();" +
1195
- " } catch(e) {" +
1196
- " console.error('Error in print:', e);" +
1197
- " }" +
1198
- " };" +
1199
- " }" +
1200
- "})();";
1151
+ """
1152
+ (function() {
1153
+ if (window.AndroidInterface) {
1154
+ // Create mobileApp object for backward compatibility
1155
+ if (!window.mobileApp) {
1156
+ window.mobileApp = {
1157
+ postMessage: function(message) {
1158
+ try {
1159
+ var msg = typeof message === 'string' ? message : JSON.stringify(message);
1160
+ window.AndroidInterface.postMessage(msg);
1161
+ } catch(e) {
1162
+ console.error('Error in mobileApp.postMessage:', e);
1163
+ }
1164
+ },
1165
+ close: function() {
1166
+ try {
1167
+ window.AndroidInterface.close();
1168
+ } catch(e) {
1169
+ console.error('Error in mobileApp.close:', e);
1170
+ }
1171
+ }
1172
+ };
1173
+ }
1174
+ // Also provide direct window methods for convenience
1175
+ window.postMessage = function(data) {
1176
+ try {
1177
+ var message = typeof data === 'string' ? data : JSON.stringify(data);
1178
+ window.AndroidInterface.postMessage(message);
1179
+ } catch(e) {
1180
+ console.error('Error in postMessage:', e);
1181
+ }
1182
+ };
1183
+ window.close = function() {
1184
+ try {
1185
+ window.AndroidInterface.close();
1186
+ } catch(e) {
1187
+ console.error('Error in close:', e);
1188
+ }
1189
+ };
1190
+ }
1191
+ // Override window.print function to use our PrintInterface
1192
+ if (window.PrintInterface) {
1193
+ window.print = function() {
1194
+ try {
1195
+ window.PrintInterface.print();
1196
+ } catch(e) {
1197
+ console.error('Error in print:', e);
1198
+ }
1199
+ };
1200
+ }
1201
+ })();
1202
+ """;
1201
1203
 
1202
1204
  _webView.post(() -> {
1203
1205
  if (_webView != null) {
@@ -1227,12 +1229,20 @@ public class WebViewDialog extends Dialog {
1227
1229
  return;
1228
1230
  }
1229
1231
 
1230
- String script =
1231
- "async function preShowFunction() {\n" +
1232
- _options.getPreShowScript() +
1233
- '\n' +
1234
- "};\n" +
1235
- "preShowFunction().then(() => window.PreShowScriptInterface.success()).catch(err => { console.error('Pre show error', err); window.PreShowScriptInterface.error(JSON.stringify(err, Object.getOwnPropertyNames(err))) })";
1232
+ String script = String.format(
1233
+ """
1234
+ async function preShowFunction() {
1235
+ %s
1236
+ }
1237
+ preShowFunction()
1238
+ .then(() => window.PreShowScriptInterface.success())
1239
+ .catch(err => {
1240
+ console.error('Pre show error', err);
1241
+ window.PreShowScriptInterface.error(JSON.stringify(err, Object.getOwnPropertyNames(err)));
1242
+ });
1243
+ """,
1244
+ _options.getPreShowScript()
1245
+ );
1236
1246
 
1237
1247
  Log.i(
1238
1248
  "InjectPreShowScript",
@@ -2214,8 +2224,44 @@ public class WebViewDialog extends Dialog {
2214
2224
  )
2215
2225
  );
2216
2226
  }
2227
+ String jsTemplate =
2228
+ """
2229
+ try {
2230
+ function getHeaders() {
2231
+ const h = {};
2232
+ %s
2233
+ return h;
2234
+ }
2235
+ window.InAppBrowserProxyRequest(new Request(atob('%s'), {
2236
+ headers: getHeaders(),
2237
+ method: '%s'
2238
+ })).then(async (res) => {
2239
+ Capacitor.Plugins.InAppBrowser.lsuakdchgbbaHandleProxiedRequest({
2240
+ ok: true,
2241
+ result: (!!res ? {
2242
+ headers: Object.fromEntries(res.headers.entries()),
2243
+ code: res.status,
2244
+ body: (await res.text())
2245
+ } : null),
2246
+ id: '%s'
2247
+ });
2248
+ }).catch((e) => {
2249
+ Capacitor.Plugins.InAppBrowser.lsuakdchgbbaHandleProxiedRequest({
2250
+ ok: false,
2251
+ result: e.toString(),
2252
+ id: '%s'
2253
+ });
2254
+ });
2255
+ } catch (e) {
2256
+ Capacitor.Plugins.InAppBrowser.lsuakdchgbbaHandleProxiedRequest({
2257
+ ok: false,
2258
+ result: e.toString(),
2259
+ id: '%s'
2260
+ });
2261
+ }
2262
+ """;
2217
2263
  String s = String.format(
2218
- "try {function getHeaders() {const h = {}; %s return h}; window.InAppBrowserProxyRequest(new Request(atob('%s'), {headers: getHeaders(), method: '%s'})).then(async (res) => Capacitor.Plugins.InAppBrowser.lsuakdchgbbaHandleProxiedRequest({ok: true, result: (!!res ? {headers: Object.fromEntries(res.headers.entries()), code: res.status, body: (await res.text())} : null), id: '%s'})).catch((e) => Capacitor.Plugins.InAppBrowser.lsuakdchgbbaHandleProxiedRequest({ok: false, result: e.toString(), id: '%s'})} catch (e) {Capacitor.Plugins.InAppBrowser.lsuakdchgbbaHandleProxiedRequest({ok: false, result: e.toString(), id: '%s'})",
2264
+ jsTemplate,
2219
2265
  headers,
2220
2266
  toBase64(request.getUrl().toString()),
2221
2267
  request.getMethod(),
@@ -2598,21 +2644,22 @@ public class WebViewDialog extends Dialog {
2598
2644
 
2599
2645
  // Clear file inputs for security/privacy before destroying WebView
2600
2646
  try {
2601
- _webView.evaluateJavascript(
2602
- "(function() {" +
2603
- " try {" +
2604
- " var inputs = document.querySelectorAll('input[type=\"file\"]');" +
2605
- " for (var i = 0; i < inputs.length; i++) {" +
2606
- " inputs[i].value = '';" +
2607
- " }" +
2608
- " return true;" +
2609
- " } catch(e) {" +
2610
- " console.log('Error clearing file inputs:', e);" +
2611
- " return false;" +
2612
- " }" +
2613
- "})();",
2614
- null
2615
- );
2647
+ String clearInputsScript =
2648
+ """
2649
+ (function() {
2650
+ try {
2651
+ var inputs = document.querySelectorAll('input[type="file"]');
2652
+ for (var i = 0; i < inputs.length; i++) {
2653
+ inputs[i].value = '';
2654
+ }
2655
+ return true;
2656
+ } catch(e) {
2657
+ console.log('Error clearing file inputs:', e);
2658
+ return false;
2659
+ }
2660
+ })();
2661
+ """;
2662
+ _webView.evaluateJavascript(clearInputsScript, null);
2616
2663
  } catch (Exception e) {
2617
2664
  Log.w(
2618
2665
  "InAppBrowser",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/inappbrowser",
3
- "version": "7.10.8",
3
+ "version": "7.10.9",
4
4
  "description": "Capacitor plugin in app browser",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",