@capgo/inappbrowser 7.10.9 → 7.10.11

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/Package.swift CHANGED
@@ -10,7 +10,7 @@ let package = Package(
10
10
  targets: ["InappbrowserPlugin"])
11
11
  ],
12
12
  dependencies: [
13
- .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.2.0")
13
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.4.2")
14
14
  ],
15
15
  targets: [
16
16
  .target(
@@ -512,43 +512,48 @@ public class WebViewDialog extends Dialog {
512
512
 
513
513
  // Fixed JavaScript with proper error handling
514
514
  String js =
515
- "try {" +
516
- " (function() {" +
517
- " var captureAttr = null;" +
518
- " // Check active element first" +
519
- " if (document.activeElement && " +
520
- " document.activeElement.tagName === 'INPUT' && " +
521
- " document.activeElement.type === 'file') {" +
522
- " if (document.activeElement.hasAttribute('capture')) {" +
523
- " captureAttr = document.activeElement.getAttribute('capture') || 'environment';" +
524
- " return captureAttr;" +
525
- " }" +
526
- " }" +
527
- " // Try to find any input with capture attribute" +
528
- " var inputs = document.querySelectorAll('input[type=\"file\"][capture]');" +
529
- " if (inputs && inputs.length > 0) {" +
530
- " captureAttr = inputs[0].getAttribute('capture') || 'environment';" +
531
- " return captureAttr;" +
532
- " }" +
533
- " // Try to extract from HTML attributes" +
534
- " var allInputs = document.getElementsByTagName('input');" +
535
- " for (var i = 0; i < allInputs.length; i++) {" +
536
- " var input = allInputs[i];" +
537
- " if (input.type === 'file') {" +
538
- " if (input.hasAttribute('capture')) {" +
539
- " captureAttr = input.getAttribute('capture') || 'environment';" +
540
- " return captureAttr;" +
541
- " }" +
542
- " // Look for the accept attribute containing image/* as this might be a camera input" +
543
- " var acceptAttr = input.getAttribute('accept');" +
544
- " if (acceptAttr && acceptAttr.indexOf('image/*') >= 0) {" +
545
- " console.log('Found input with image/* accept');" +
546
- " }" +
547
- " }" +
548
- " }" +
549
- " return '';" +
550
- " })();" +
551
- "} catch(e) { console.error('Capture detection error:', e); return ''; }";
515
+ """
516
+ try {
517
+ (function() {
518
+ var captureAttr = null;
519
+ // Check active element first
520
+ if (document.activeElement &&
521
+ document.activeElement.tagName === 'INPUT' &&
522
+ document.activeElement.type === 'file') {
523
+ if (document.activeElement.hasAttribute('capture')) {
524
+ captureAttr = document.activeElement.getAttribute('capture') || 'environment';
525
+ return captureAttr;
526
+ }
527
+ }
528
+ // Try to find any input with capture attribute
529
+ var inputs = document.querySelectorAll('input[type="file"][capture]');
530
+ if (inputs && inputs.length > 0) {
531
+ captureAttr = inputs[0].getAttribute('capture') || 'environment';
532
+ return captureAttr;
533
+ }
534
+ // Try to extract from HTML attributes
535
+ var allInputs = document.getElementsByTagName('input');
536
+ for (var i = 0; i < allInputs.length; i++) {
537
+ var input = allInputs[i];
538
+ if (input.type === 'file') {
539
+ if (input.hasAttribute('capture')) {
540
+ captureAttr = input.getAttribute('capture') || 'environment';
541
+ return captureAttr;
542
+ }
543
+ // Look for the accept attribute containing image/* as this might be a camera input
544
+ var acceptAttr = input.getAttribute('accept');
545
+ if (acceptAttr && acceptAttr.indexOf('image/*') >= 0) {
546
+ console.log('Found input with image/* accept');
547
+ }
548
+ }
549
+ }
550
+ return '';
551
+ })();
552
+ } catch(e) {
553
+ console.error('Capture detection error:', e);
554
+ return '';
555
+ }
556
+ """;
552
557
 
553
558
  webView.evaluateJavascript(js, value -> {
554
559
  Log.d("InAppBrowser", "Capture attribute JS result: " + value);
@@ -443,11 +443,20 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
443
443
 
444
444
  // Method to send a message from Swift to JavaScript
445
445
  open func postMessageToJS(message: [String: Any]) {
446
- if let jsonData = try? JSONSerialization.data(withJSONObject: message, options: []),
447
- let jsonString = String(data: jsonData, encoding: .utf8) {
448
- let script = "window.dispatchEvent(new CustomEvent('messageFromNative', { detail: \(jsonString) }));"
449
- DispatchQueue.main.async {
450
- self.webView?.evaluateJavaScript(script, completionHandler: nil)
446
+ guard let jsonData = try? JSONSerialization.data(withJSONObject: message, options: []),
447
+ let jsonString = String(data: jsonData, encoding: .utf8) else {
448
+ print("[InAppBrowser] Failed to serialize message to JSON")
449
+ return
450
+ }
451
+
452
+ // Safely build the script to avoid any potential issues
453
+ let script = "window.dispatchEvent(new CustomEvent('messageFromNative', { detail: \(jsonString) }));"
454
+
455
+ DispatchQueue.main.async {
456
+ self.webView?.evaluateJavaScript(script) { result, error in
457
+ if let error = error {
458
+ print("[InAppBrowser] JavaScript evaluation error in postMessageToJS: \(error)")
459
+ }
451
460
  }
452
461
  }
453
462
  }
@@ -1339,20 +1348,25 @@ extension WKWebViewController: WKNavigationDelegate {
1339
1348
  return
1340
1349
  }
1341
1350
 
1342
- // TODO: implement interface
1343
- let script = """
1344
- async function preShowFunction() {
1345
- \(self.preShowScript ?? "")
1346
- };
1347
- preShowFunction().then(
1348
- () => window.webkit.messageHandlers.preShowScriptSuccess.postMessage({})
1349
- ).catch(
1350
- err => {
1351
- console.error('Preshow error', err);
1352
- window.webkit.messageHandlers.preShowScriptError.postMessage(JSON.stringify(err, Object.getOwnPropertyNames(err)));
1353
- }
1354
- )
1355
- """
1351
+ // Safely construct script template with proper escaping
1352
+ let userScript = self.preShowScript ?? ""
1353
+
1354
+ // Build script using safe concatenation to avoid multi-line string issues
1355
+ let scriptTemplate = [
1356
+ "async function preShowFunction() {",
1357
+ userScript,
1358
+ "}",
1359
+ "preShowFunction().then(",
1360
+ " () => window.webkit.messageHandlers.preShowScriptSuccess.postMessage({})",
1361
+ ").catch(",
1362
+ " err => {",
1363
+ " console.error('Preshow error', err);",
1364
+ " window.webkit.messageHandlers.preShowScriptError.postMessage(JSON.stringify(err, Object.getOwnPropertyNames(err)));",
1365
+ " }",
1366
+ ")"
1367
+ ]
1368
+
1369
+ let script = scriptTemplate.joined(separator: "\n")
1356
1370
  print("[InAppBrowser - InjectPreShowScript] PreShowScript script: \(script)")
1357
1371
 
1358
1372
  self.preShowSemaphore = DispatchSemaphore(value: 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/inappbrowser",
3
- "version": "7.10.9",
3
+ "version": "7.10.11",
4
4
  "description": "Capacitor plugin in app browser",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",