@capgo/capacitor-inappbrowser 8.10.3 → 8.10.5-beta.pr624.490.1
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/README.md +68 -68
- package/android/src/main/java/ee/forgr/capacitor_inappbrowser/SafeAreaInsetsSupport.java +13 -0
- package/android/src/main/java/ee/forgr/capacitor_inappbrowser/WebViewDialog.java +15 -3
- package/dist/docs.json +3 -3
- package/dist/esm/definitions.d.ts +13 -6
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Sources/InAppBrowserPlugin/InAppBrowserPlugin.swift +94 -60
- package/ios/Sources/InAppBrowserPlugin/WKWebViewController.swift +62 -37
- package/package.json +1 -1
|
@@ -47,6 +47,35 @@ private enum BlobDownloadSupport {
|
|
|
47
47
|
static let chunkBytes = 64 * 1024
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/// Script message handlers registered on every in-app browser WKWebView.
|
|
51
|
+
/// Popup configs from `createWebViewWith` copy parent handlers, so we must
|
|
52
|
+
/// remove these names before re-adding or WKWebView raises NSInvalidArgumentException.
|
|
53
|
+
enum ScriptMessageHandlerSupport {
|
|
54
|
+
static let allNames = [
|
|
55
|
+
"messageHandler",
|
|
56
|
+
"preShowScriptError",
|
|
57
|
+
"preShowScriptSuccess",
|
|
58
|
+
"close",
|
|
59
|
+
"hide",
|
|
60
|
+
"show",
|
|
61
|
+
"blobDownload",
|
|
62
|
+
"blobDownloadStart",
|
|
63
|
+
"blobDownloadChunk",
|
|
64
|
+
"blobDownloadFinish",
|
|
65
|
+
"blobDownloadAbort",
|
|
66
|
+
"takeScreenshot",
|
|
67
|
+
"consoleMessageHandler",
|
|
68
|
+
"magicPrint",
|
|
69
|
+
"capgoProxyBridge"
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
static func removeAll(from userContentController: WKUserContentController) {
|
|
73
|
+
for name in allNames {
|
|
74
|
+
userContentController.removeScriptMessageHandler(forName: name)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
50
79
|
private struct BlobDownloadSession {
|
|
51
80
|
let destinationURL: URL
|
|
52
81
|
let sourceURL: String?
|
|
@@ -2008,16 +2037,7 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
2008
2037
|
}
|
|
2009
2038
|
let userContentController = webConfiguration.userContentController
|
|
2010
2039
|
userContentController.removeAllUserScripts()
|
|
2011
|
-
|
|
2012
|
-
userContentController.removeScriptMessageHandler(forName: "preShowScriptError")
|
|
2013
|
-
userContentController.removeScriptMessageHandler(forName: "preShowScriptSuccess")
|
|
2014
|
-
userContentController.removeScriptMessageHandler(forName: "close")
|
|
2015
|
-
userContentController.removeScriptMessageHandler(forName: "hide")
|
|
2016
|
-
userContentController.removeScriptMessageHandler(forName: "show")
|
|
2017
|
-
userContentController.removeScriptMessageHandler(forName: "takeScreenshot")
|
|
2018
|
-
userContentController.removeScriptMessageHandler(forName: "consoleMessageHandler")
|
|
2019
|
-
userContentController.removeScriptMessageHandler(forName: "magicPrint")
|
|
2020
|
-
userContentController.removeScriptMessageHandler(forName: "capgoProxyBridge")
|
|
2040
|
+
ScriptMessageHandlerSupport.removeAll(from: userContentController)
|
|
2021
2041
|
|
|
2022
2042
|
if proxyRequests || proxySchemeHandler != nil, let handler = proxySchemeHandler {
|
|
2023
2043
|
WKWebView.enableCustomSchemeHandling(for: ["https", "http"])
|
|
@@ -2264,7 +2284,9 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
2264
2284
|
self.enabledSafeTopMargin = parent.enabledSafeTopMargin
|
|
2265
2285
|
self.blockedHosts = parent.blockedHosts
|
|
2266
2286
|
self.authorizedAppLinks = parent.authorizedAppLinks
|
|
2267
|
-
|
|
2287
|
+
// createWebViewWith configs copy parent script handlers; start clean so
|
|
2288
|
+
// initWebview can register blobDownload/etc without NSInvalidArgumentException.
|
|
2289
|
+
configuration.userContentController = WKUserContentController()
|
|
2268
2290
|
self.initialWebConfiguration = configuration
|
|
2269
2291
|
self.persistWebViewData = parent.persistWebViewData
|
|
2270
2292
|
self.disableOverscroll = parent.disableOverscroll
|
|
@@ -2548,20 +2570,7 @@ public extension WKWebViewController {
|
|
|
2548
2570
|
webView.loadHTMLString("", baseURL: nil)
|
|
2549
2571
|
|
|
2550
2572
|
webView.configuration.userContentController.removeAllUserScripts()
|
|
2551
|
-
webView.configuration.userContentController
|
|
2552
|
-
webView.configuration.userContentController.removeScriptMessageHandler(forName: "close")
|
|
2553
|
-
webView.configuration.userContentController.removeScriptMessageHandler(forName: "hide")
|
|
2554
|
-
webView.configuration.userContentController.removeScriptMessageHandler(forName: "show")
|
|
2555
|
-
if allowScreenshotsFromWebPage {
|
|
2556
|
-
webView.configuration.userContentController.removeScriptMessageHandler(forName: "takeScreenshot")
|
|
2557
|
-
}
|
|
2558
|
-
if captureConsoleLogs {
|
|
2559
|
-
webView.configuration.userContentController.removeScriptMessageHandler(forName: "consoleMessageHandler")
|
|
2560
|
-
}
|
|
2561
|
-
webView.configuration.userContentController.removeScriptMessageHandler(forName: "preShowScriptSuccess")
|
|
2562
|
-
webView.configuration.userContentController.removeScriptMessageHandler(forName: "preShowScriptError")
|
|
2563
|
-
webView.configuration.userContentController.removeScriptMessageHandler(forName: "magicPrint")
|
|
2564
|
-
webView.configuration.userContentController.removeScriptMessageHandler(forName: "capgoProxyBridge")
|
|
2573
|
+
ScriptMessageHandlerSupport.removeAll(from: webView.configuration.userContentController)
|
|
2565
2574
|
|
|
2566
2575
|
webView.removeFromSuperview()
|
|
2567
2576
|
// Also clean progress bar view if present
|
|
@@ -2830,8 +2839,9 @@ fileprivate extension WKWebViewController {
|
|
|
2830
2839
|
private func tryOpenCustomScheme(_ url: URL) -> Bool {
|
|
2831
2840
|
let app = UIApplication.shared
|
|
2832
2841
|
let shouldEmitCustomSchemeEvent = CustomSchemeInterceptSupport.shouldEmitInterceptEvent(for: url)
|
|
2842
|
+
let canOpen = app.canOpenURL(url)
|
|
2833
2843
|
|
|
2834
|
-
if
|
|
2844
|
+
if CustomSchemeOpenSupport.shouldAttemptOpen(scheme: url.scheme, canOpenURL: canOpen) {
|
|
2835
2845
|
app.open(url, options: [:], completionHandler: nil)
|
|
2836
2846
|
if shouldEmitCustomSchemeEvent {
|
|
2837
2847
|
emit("customSchemeIntercepted", data: ["url": url.absoluteString, "opened": true])
|
|
@@ -2847,10 +2857,22 @@ fileprivate extension WKWebViewController {
|
|
|
2847
2857
|
return true
|
|
2848
2858
|
}
|
|
2849
2859
|
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2860
|
+
/// Prefer Universal Links into the native app; if that fails, hand off to the system
|
|
2861
|
+
/// (App Store, Safari, etc.) before falling back to in-webview loading.
|
|
2862
|
+
private func openAuthorizedAppLink(_ url: URL, completion: @escaping (Bool) -> Void) {
|
|
2863
|
+
UIApplication.shared.open(url, options: [.universalLinksOnly: true]) { universalLinkOpened in
|
|
2864
|
+
if universalLinkOpened {
|
|
2865
|
+
completion(true)
|
|
2866
|
+
return
|
|
2867
|
+
}
|
|
2868
|
+
|
|
2869
|
+
UIApplication.shared.open(url, options: [:]) { systemOpenSucceeded in
|
|
2870
|
+
let outcome = AuthorizedAppLinkOpenSupport.resolve(
|
|
2871
|
+
universalLinkOpened: false,
|
|
2872
|
+
systemOpenSucceeded: systemOpenSucceeded
|
|
2873
|
+
)
|
|
2874
|
+
completion(outcome == .openedExternally)
|
|
2875
|
+
}
|
|
2854
2876
|
}
|
|
2855
2877
|
}
|
|
2856
2878
|
|
|
@@ -2954,12 +2976,12 @@ fileprivate extension WKWebViewController {
|
|
|
2954
2976
|
return
|
|
2955
2977
|
}
|
|
2956
2978
|
|
|
2957
|
-
// Authorized
|
|
2979
|
+
// Authorized App Link hosts: Universal Link first, then system open.
|
|
2958
2980
|
print("[InAppBrowser] Authorized App Links: \(self.authorizedAppLinks)")
|
|
2959
2981
|
if isUrlAuthorized(url, authorizedLinks: self.authorizedAppLinks) {
|
|
2960
|
-
print("[InAppBrowser] Authorized
|
|
2961
|
-
|
|
2962
|
-
print("[InAppBrowser]
|
|
2982
|
+
print("[InAppBrowser] Authorized App Link detected \(scheme + host), try to open URLs in external apps")
|
|
2983
|
+
openAuthorizedAppLink(url) { opened in
|
|
2984
|
+
print("[InAppBrowser] Authorized App Link opened externally: \(opened)")
|
|
2963
2985
|
completion(opened) // opened => cancel navigation; not opened => allow WebView
|
|
2964
2986
|
}
|
|
2965
2987
|
return
|
|
@@ -3255,8 +3277,8 @@ extension WKWebViewController: WKUIDelegate {
|
|
|
3255
3277
|
isAuthorizedAppLink: isAuthorized
|
|
3256
3278
|
) {
|
|
3257
3279
|
case .openExternalApp:
|
|
3258
|
-
// Prefer
|
|
3259
|
-
|
|
3280
|
+
// Prefer native app / Universal Link, then system open (App Store / Safari).
|
|
3281
|
+
openAuthorizedAppLink(url) { [weak webView] opened in
|
|
3260
3282
|
if !opened {
|
|
3261
3283
|
DispatchQueue.main.async {
|
|
3262
3284
|
webView?.load(navigationAction.request)
|
|
@@ -3552,7 +3574,10 @@ extension WKWebViewController: WKNavigationDelegate {
|
|
|
3552
3574
|
return
|
|
3553
3575
|
}
|
|
3554
3576
|
|
|
3555
|
-
|
|
3577
|
+
let appStoreHosts = ["apps.apple.com", "itunes.apple.com"]
|
|
3578
|
+
if !self.preventDeeplink,
|
|
3579
|
+
let appStoreHost = self.normalizeHost(url.host),
|
|
3580
|
+
appStoreHosts.contains(appStoreHost) {
|
|
3556
3581
|
UIApplication.shared.open(url, options: [:], completionHandler: nil)
|
|
3557
3582
|
decisionHandler(.cancel)
|
|
3558
3583
|
return
|