Dont crash if clicking on a fragment link

If a user clicks on a fragment link like <a href="#info">click here to skip to info</a>
we would previously crash because we would reload the bundle.

This prevents the crash but the link does not work, we can't
just synthesize these links with JS, because the id="info" items
are usually removed by readability.

To properly handle this, we probably need to preserve some id
elements if they are linked to. Then we can scroll to those elements
in Javascript.
This commit is contained in:
Jackson Harper 2022-12-06 10:58:01 +08:00
parent da4f880ce4
commit 66fc258e0c

View file

@ -62,7 +62,7 @@ extension WebReaderCoordinator: WKNavigationDelegate {
// swiftlint:disable:next line_length
func webView(_: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if navigationAction.navigationType == .linkActivated {
if let linkURL = navigationAction.request.url {
if let linkURL = navigationAction.request.url, !linkURL.isFileURL {
linkHandler(linkURL)
}
decisionHandler(.cancel)