@capgo/inappbrowser 7.7.1 → 7.7.2
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.
|
@@ -478,7 +478,20 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
478
478
|
semaphore.signal()
|
|
479
479
|
} else if message.name == "close" {
|
|
480
480
|
closeView()
|
|
481
|
-
|
|
481
|
+
} else if message.name == "magicPrint" {
|
|
482
|
+
if let webView = self.webView {
|
|
483
|
+
let printController = UIPrintInteractionController.shared
|
|
484
|
+
|
|
485
|
+
let printInfo = UIPrintInfo(dictionary: nil)
|
|
486
|
+
printInfo.outputType = .general
|
|
487
|
+
printInfo.jobName = "Print Job"
|
|
488
|
+
|
|
489
|
+
printController.printInfo = printInfo
|
|
490
|
+
printController.printFormatter = webView.viewPrintFormatter()
|
|
491
|
+
|
|
492
|
+
printController.present(animated: true, completionHandler: nil)
|
|
493
|
+
}
|
|
494
|
+
}
|
|
482
495
|
}
|
|
483
496
|
|
|
484
497
|
func injectJavaScriptInterface() {
|
|
@@ -496,9 +509,17 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
496
509
|
};
|
|
497
510
|
}
|
|
498
511
|
"""
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
512
|
+
DispatchQueue.main.async {
|
|
513
|
+
self.webView?.evaluateJavaScript(script) { result, error in
|
|
514
|
+
if let error = error {
|
|
515
|
+
print("JavaScript evaluation error: \(error)")
|
|
516
|
+
} else if let result = result {
|
|
517
|
+
print("JavaScript result: \(result)")
|
|
518
|
+
} else {
|
|
519
|
+
print("JavaScript executed with no result")
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
502
523
|
}
|
|
503
524
|
|
|
504
525
|
open func initWebview(isInspectable: Bool = true) {
|
|
@@ -513,14 +534,35 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
513
534
|
userContentController.add(self, name: "preShowScriptError")
|
|
514
535
|
userContentController.add(self, name: "preShowScriptSuccess")
|
|
515
536
|
userContentController.add(self, name: "close")
|
|
537
|
+
userContentController.add(self, name: "magicPrint")
|
|
538
|
+
|
|
539
|
+
// Inject JavaScript to override window.print
|
|
540
|
+
let script = WKUserScript(
|
|
541
|
+
source: """
|
|
542
|
+
window.print = function() {
|
|
543
|
+
window.webkit.messageHandlers.magicPrint.postMessage('magicPrint');
|
|
544
|
+
};
|
|
545
|
+
""",
|
|
546
|
+
injectionTime: .atDocumentStart,
|
|
547
|
+
forMainFrameOnly: false
|
|
548
|
+
)
|
|
549
|
+
userContentController.addUserScript(script)
|
|
550
|
+
|
|
516
551
|
webConfiguration.allowsInlineMediaPlayback = true
|
|
517
552
|
webConfiguration.userContentController = userContentController
|
|
553
|
+
|
|
518
554
|
let webView = WKWebView(frame: .zero, configuration: webConfiguration)
|
|
519
555
|
|
|
520
|
-
if webView.responds(to: Selector(("setInspectable:"))) {
|
|
521
|
-
// Fix: https://stackoverflow.com/questions/76216183/how-to-debug-wkwebview-in-ios-16-4-1-using-xcode-14-2/76603043#76603043
|
|
522
|
-
webView.perform(Selector(("setInspectable:")), with: isInspectable)
|
|
523
|
-
}
|
|
556
|
+
// if webView.responds(to: Selector(("setInspectable:"))) {
|
|
557
|
+
// // Fix: https://stackoverflow.com/questions/76216183/how-to-debug-wkwebview-in-ios-16-4-1-using-xcode-14-2/76603043#76603043
|
|
558
|
+
// webView.perform(Selector(("setInspectable:")), with: isInspectable)
|
|
559
|
+
// }
|
|
560
|
+
|
|
561
|
+
if #available(iOS 16.4, *) {
|
|
562
|
+
webView.isInspectable = true
|
|
563
|
+
} else {
|
|
564
|
+
// Fallback on earlier versions
|
|
565
|
+
}
|
|
524
566
|
|
|
525
567
|
if self.blankNavigationTab {
|
|
526
568
|
// First add the webView to view hierarchy
|