@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
|
|
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
|
-
"
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
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
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
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
|
-
//
|
|
1343
|
-
let
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
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)
|