Reputation: 5460
I've loaded a page and am looking for all the <script>
with type=text/javascript
, but no matter what I do I get an exception
webView.evaluateJavaScript("document.querySelectorAll('script[type=text\\/javascript]').length;)
The string did not match the expected pattern.
webView.evaluateJavaScript("document.querySelectorAll('script[type=text/javascript]').length;)
The string did not match the expected pattern.
webView.evaluateJavaScript("document.querySelectorAll('script').length;)
19
Got no clue how to add a type filter in there, it works in the Console in Safari
Upvotes: 0
Views: 3084
Reputation: 4037
It works for me
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
webView.evaluateJavaScript("document.querySelectorAll('script[type=\"text/javascript\"]').length;") { result, err in
print(result ?? "")
print(err ?? "")
}
}
@VedantBang's comment matters
Upvotes: 1