Detect UI element of website in WKWebView iOS

401 Views Asked by At

If I am open website in WKWebKit, and this website have a banners with ads I can detect link of this banners when click on it?

For example, if I am open this website ( https://123moviesfree.net/home ) on google chrome on PC and I am select any movies, and when I clicked on movie I am open ads on next window.

How I am can get link of banner when clicked on element of website inside WKWebView?

If simple, I can get link of all banners etc while page is load BUT how than detect on which element user than click?

1

There are 1 best solutions below

0
On BEST ANSWER

For detecting ads banners of page I am use WKUIDelegate

and function:

func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? 

And then I use

navigationAction.targetFrame?.isMainFrame
navigationAction.sourceFrame.request.url

for detecting link of all UI element of page