fix(macos): avoid external open for about:blank

This commit is contained in:
Peter Steinberger
2025-12-12 21:56:54 +00:00
parent d8cb1daa78
commit 61085f6141

View File

@@ -311,11 +311,32 @@ final class CanvasWindowController: NSWindowController, WKNavigationDelegate, NS
return
}
let scheme = url.scheme?.lowercased()
if scheme == CanvasScheme.scheme || scheme == "https" || scheme == "http" {
// Keep web content inside the panel when reasonable.
// `about:blank` and friends are common internal navigations for WKWebView; never send them to NSWorkspace.
if scheme == CanvasScheme.scheme
|| scheme == "https"
|| scheme == "http"
|| scheme == "about"
|| scheme == "blob"
|| scheme == "data"
|| scheme == "javascript"
{
decisionHandler(.allow)
return
}
NSWorkspace.shared.open(url)
// Only open external URLs when there is a registered handler, otherwise macOS will show a confusing
// "There is no application set to open the URL ..." alert (e.g. for about:blank).
if let appURL = NSWorkspace.shared.urlForApplication(toOpen: url) {
NSWorkspace.shared.open(
[url],
withApplicationAt: appURL,
configuration: NSWorkspace.OpenConfiguration(),
completionHandler: nil)
} else {
canvasWindowLogger.debug("no application to open url \(url.absoluteString, privacy: .public)")
}
decisionHandler(.cancel)
}