Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions Sources/SaaSquatchWebView/SaaSquatchWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftyJSON
import WebKit
import SaaSquatch

public class SaaSquatchWebView: WKWebView, WKUIDelegate {
public class SaaSquatchWebView: WKWebView, WKUIDelegate, WKNavigationDelegate {
public var client: SaaSquatchClient?

/**
Expand Down Expand Up @@ -86,9 +86,12 @@ public class SaaSquatchWebView: WKWebView, WKUIDelegate {
}
}

private static let externalSchemes: Set<String> = ["mailto", "sms", "tel"]

private func setWebViewContent(html: String) {
DispatchQueue.main.async {
self.uiDelegate = self
self.navigationDelegate = self
let htmlWithMeta = html.replacingOccurrences(of: "</head>", with: "<meta name=\"viewport\" content=\"initial-scale=1.0\" /></head>")
self.loadHTMLString(htmlWithMeta, baseURL: URL(string: "https://fast.ssqt.io"))
}
Expand Down Expand Up @@ -124,12 +127,26 @@ public class SaaSquatchWebView: WKWebView, WKUIDelegate {
for navigationAction: WKNavigationAction,
windowFeatures: WKWindowFeatures) -> WKWebView? {
if let url = navigationAction.request.url, navigationAction.targetFrame == nil {
if url.scheme == "http" || url.scheme == "https" || url.scheme == "mailto" {
if url.scheme == "http" || url.scheme == "https"
|| Self.externalSchemes.contains(url.scheme ?? "") {
UIApplication.shared.open(url)
}
}
return nil
}

public func webView(_ webView: WKWebView,
decidePolicyFor navigationAction: WKNavigationAction,
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if let url = navigationAction.request.url,
let scheme = url.scheme,
Self.externalSchemes.contains(scheme) {
UIApplication.shared.open(url)
Comment on lines +141 to +144

Copilot AI Apr 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL.scheme is case-insensitive by spec, but the externalSchemes lookup is currently case-sensitive. This can fail to intercept links like TEL:/MailTo: coming from HTML. Consider normalizing the scheme (e.g., compare scheme.lowercased() against the set) before checking membership.

Copilot uses AI. Check for mistakes.
decisionHandler(.cancel)
return
}
decisionHandler(.allow)
}
}

let ERROR_HTML_TEMPLATE = """
Expand Down
Loading