Skip to content

Commit

Permalink
fix(ios): Add check for both serverURL and localURL in navigation (#5736
Browse files Browse the repository at this point in the history
)

fix(ios): Add check for both serverURL and localURL in navigation decision policy for `WebViewDelegationHandler`.
  • Loading branch information
Steven0351 committed Jul 5, 2022
1 parent c5d6328 commit 8e824f3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ios/Capacitor/Capacitor/WebViewDelegationHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ internal class WebViewDelegationHandler: NSObject, WKNavigationDelegate, WKUIDel

// otherwise, is this a new window or a main frame navigation but to an outside source
let toplevelNavigation = (navigationAction.targetFrame == nil || navigationAction.targetFrame?.isMainFrame == true)
if navURL.absoluteString.contains(bridge.config.serverURL.absoluteString) == false, toplevelNavigation {

// Check if the url being navigated to is configured as an application url (whether local or remote)
let isApplicationNavigation = navURL.absoluteString.starts(with: bridge.config.serverURL.absoluteString) ||
navURL.absoluteString.starts(with: bridge.config.localURL.absoluteString)

if !isApplicationNavigation, toplevelNavigation {
// disallow and let the system handle it
if UIApplication.shared.applicationState == .active {
UIApplication.shared.open(navURL, options: [:], completionHandler: nil)
Expand Down

0 comments on commit 8e824f3

Please sign in to comment.