When clicking some navigation link, "decidePolicyForNavigationAction:" will return (WKNavigationAction *)navigationAction to determine URL request and other info, etc.
I want to know the x, y position of the clicking on the WKWebView. I print out "navigationAction.description" below, there seem to be some position info?
How do I get that "position" info? Or better, can navigationAction to have this position property I can retrieve?
Vincent
<WKNavigationAction: 0x7faef025b870; navigationType = 0; syntheticClickType = 1; position x = 412.00 y = 187.00 request = <NSMutableURLRequest: 0x600001d66070> { URL: $dG2192 }; sourceFrame = <WKFrameInfo: 0x7faef02b4a70; webView = 0x7faef0824c00; isMainFrame = YES; request = <NSMutableURLRequest: 0x600001d0cbf0> { URL: about:blank }>; targetFrame = <WKFrameInfo: 0x7faef02b4a70; webView = 0x7faef0824c00; isMainFrame = YES; request = <NSMutableURLRequest: 0x600001d0cbf0> { URL: about:blank }>>
let str2 = str.slice(from: "position", to: "request")
let xCor = str2?.slice(from: "= ", to:" y")
let yCor = str2?.slice(from: "y = ", to: " ")
let xVal = Double(xCor!)
let yVal = Double(yCor!)
extension String {
func slice(from: String, to: String) -> String? {
return (range(of: from)?.upperBound).flatMap { substringFrom in
(range(of: to, range: substringFrom..<endIndex)?.lowerBound).map { substringTo in
String(self[substringFrom..<substringTo])
}
}
}
}
Hi,
I used this code to separate the x and y coordinate from the description string provided. This is a workaround as I could not find anything better for now. Please let me know if anyone has better solution to this problem.