Search code examples
iosswiftwebviewwkwebview

Accessing wkwebview's backForwardList.backList or backForwardList.forwardList for second time causes crash


I'm trying to access wkWebview's backList, I've written the code below to find it. The code below works fine whenever I'm trying to access it for the first time, but when I again try to access wkwebview's backlist for second time I get a crash of bad access with the code: EXC_I386_GPFLT

Below is my code which I've written:

let backList = webView.backForwardList.backList
let count = backList.count
for item in backList[0..<count] {
    print(item.title)
}

I get the crash at the first line. Can anyone please guide me what can be the cause of crash?


Solution

  • have you tried something like this

    for page in webView.backForwardList.backList {
        print("User visited \(page.title) \(page.url.absoluteString)")
    }