Questions tagged [wknavigationdelegate]

WKNavigationDelegate is a protocol in WebKit. It can be used from macOS and iOS as well. It helps implementing behaviors triggered in a WKWebView during navigation, including accepting, loading and completing a request.

Apple Developer Documentation

16 questions
28
votes
3 answers

Get the current full URL for WKWebView

Is there a way to get the FULL URL loaded by a WKWebView for every request? webView:didFinishNavigation: Works only for mainFrame navigations and does not provide a URL request parameter. How do I get the FULL URL just like in…
i-konov
  • 794
  • 1
  • 6
  • 18
2
votes
2 answers

How do I convert a WKScriptMessage.body to a struct?

I set up the WKScriptMessageHandler function userContentController(WKUserContentController, didReceive: WKScriptMessage) to handle JavaScript messages sent to the native app. I know ahead of time that the message body will always come back with the…
rawbee
  • 2,756
  • 3
  • 13
  • 21
2
votes
1 answer

Unit testing WKNavigationDelegate functions swift

I have a UIViewController that implements some WKNavigationDelegate functions, and I want to unit test the logic in these functions. Here's an example: func webView(_ webView: WKWebView, decidePolicyFor navigationAction:…
2
votes
0 answers

WKWebView's didFinish delegate method is taking too long to receive the callback

I have a WKWebView inside my UITableViewCell. I configure my webview with an HTML string as follows: webView.loadHTMLString(myHTMLString, baseURL: URL(string: "http://www.myPage.com")) I am expecting to receive the callback in the following…
1
vote
0 answers

Xamarin.iOS WKWebView and WKNavigationDelegate custom renderer Intranet SharePoint links not working

I am working on one Xamarin forms app and I have created custom renderer to use native web views. We have some intranet SharePoint URL links in web view content which is not working in iPhone real device. The public URL links are working fine but…
1
vote
2 answers

Stop navigation WKWebview

This is my situation: I have a view controller within a WKWebView. This webview starts with a page "A". In this page there are some links (href) and I want that for some of these links must open in the external browser. For this reason I set the…
gianni rodari
  • 47
  • 1
  • 7
1
vote
1 answer

Cocoa Swift: Error evaluateJavaScript Optional("A JavaScript exception occurred")

I'm loading WKWebView with a webpage and I'm trying to execute javascrip: func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { webView.evaluateJavaScript("document.getElementById('someElement').innerText") { (result,…
user2924482
  • 6,844
  • 16
  • 65
  • 133
0
votes
0 answers

iOS : how to write unit test for didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error

func webView( _ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error ) { //show alert } need to write unit test when didFailProvisionalNavigation fails with error
dmn
  • 11
  • 2
0
votes
1 answer

How can I know if external app will be open or not when a link is loaded in WKWebView?

I have a WKWebView, the webview will load a link like https://qr.payme.hsbc.com/2/XXXXYYYZZZ. And there two possible results when the link is loaded, case 1 is an app called Payme will be opened when user has installed Payme app; case 2 is webview…
Season
  • 1,038
  • 1
  • 16
  • 39
0
votes
0 answers

WKWebView “goback” function does not execute refresh and javascript code

I have a ViewController that is embedded in a NavigationController and this ViewController adds WKWebView as a subview. The problem is that after navigating to any web page; if I call the function "goback", the previous page will be present and…
0
votes
1 answer

Unable to open external link in safari using WKWebView

I am migrating from UIWebView to WKWebView. Need to load HTML content in WKWebView everything is working fine but the problem is unable to open link in the external safari browser after a click on any link from WKWebView. I used below…
0
votes
1 answer

WKWebView intercept local file requests

I have a WKWebView in my iOS 11+ app where I need to load custom HTML from local in-memory HTML. I can accomplish this by using webView.loadHTMLString or webview.load(data), which is working fine. This HTML references some required .js/.css/.png…
Henrik
  • 406
  • 3
  • 13
0
votes
1 answer

WKWebView is empty if I implement decidePolicyFor navigationAction, loads correctly if I remove the function

This is in xcode 10.3, swift 5 I'm trying to load some web content using WKWebView. I have a class that is just NSObject, which implements the WKNavigationDelegate class. I create the web view Set the navigationDelegate Load the web view If I…
0
votes
1 answer

Saving html data in variable from completion handler in Swift WKWebView

I'm trying to scrape data from a website, and the data I want is in a span tag. So far, what I've done is: var str: Any? webView.evaluateJavaScript("innerDoc.getElementById(spanId).innerHTML", completionHandler: { (html: Any?, error: Error?)…
1
2