2

I'm implementing a tiny browser, so I would like to be able to navigate back and forward on my web view. For these purposes I use WKWebView, but I need to display an Error html page sometimes, and I don't want this page to be stored in my WKBackForwardList.

Is there any way to remove one item from WKBackForwardList ? I guess that it is a really general issue, so, do I have to implement my own History functional?

BergP
  • 3,453
  • 4
  • 33
  • 58

2 Answers2

3

It is clear for now that WKBackForwardList is immutable (e.g. cannot be modified). But you can achieve this result by messing up with local webserver. You create an error page, served by local webserver and load it in a webview in case of error. But the behaviour of the local webserver is so that it loads the error page once and all the other requests (from going back and forward) will lead to a redirect to the page which caused the error. BackFrowardList do not store duplicates of the url addresses in a sequence so this page URL will appear only once. Take a look at Firefox iOS version implementation because they use the exact same technique.

On the history part, if you only want the history to persist during one session you can really make use of BackForwardList items. But if you want to persist the history between sessions (WKWebView destruction) you'll have to make your own history storage.

Denis Z
  • 133
  • 9
0

As I know

func loadHTMLString(_ string: String,
        baseURL baseURL: NSURL?) -> WKNavigation?

dosen't add stuff to the list, canGoBack and canGoForward returns false, so the error page could be added as string.

Peter Ahlberg
  • 1,359
  • 2
  • 24
  • 26