From aab744687aa3d48dacd6e5967dc8a753f55202d4 Mon Sep 17 00:00:00 2001 From: Steven Sherry Date: Wed, 18 Oct 2023 12:02:21 -0500 Subject: [PATCH] fix(ios): Bring CAPWebView WKWebView configuration up to par with CAPBridgeViewController --- ios/Capacitor/Capacitor/CAPWebView.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ios/Capacitor/Capacitor/CAPWebView.swift b/ios/Capacitor/Capacitor/CAPWebView.swift index 131a2ecdb3..241fbe8903 100644 --- a/ios/Capacitor/Capacitor/CAPWebView.swift +++ b/ios/Capacitor/Capacitor/CAPWebView.swift @@ -135,6 +135,11 @@ extension CAPWebView { webViewConfiguration.suppressesIncrementalRendering = false webViewConfiguration.allowsAirPlayForMediaPlayback = true webViewConfiguration.mediaTypesRequiringUserActionForPlayback = [] + + if #available(iOS 14.0, *) { + webViewConfiguration.limitsNavigationsToAppBoundDomains = instanceConfiguration.limitsNavigationsToAppBoundDomains + } + if let appendUserAgent = instanceConfiguration.appendedUserAgentString { if let appName = webViewConfiguration.applicationNameForUserAgent { webViewConfiguration.applicationNameForUserAgent = "\(appName) \(appendUserAgent)" @@ -142,6 +147,17 @@ extension CAPWebView { webViewConfiguration.applicationNameForUserAgent = appendUserAgent } } + + if let preferredContentMode = instanceConfiguration.preferredContentMode { + var mode = WKWebpagePreferences.ContentMode.recommended + if preferredContentMode == "mobile" { + mode = WKWebpagePreferences.ContentMode.mobile + } else if preferredContentMode == "desktop" { + mode = WKWebpagePreferences.ContentMode.desktop + } + webViewConfiguration.defaultWebpagePreferences.preferredContentMode = mode + } + return webViewConfiguration }