fix(macos): avoid external open for about:blank
parent
d8cb1daa78
commit
61085f6141
|
|
@ -311,11 +311,32 @@ final class CanvasWindowController: NSWindowController, WKNavigationDelegate, NS
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let scheme = url.scheme?.lowercased()
|
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)
|
decisionHandler(.allow)
|
||||||
return
|
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)
|
decisionHandler(.cancel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue