0

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

1
  • You missed quotes around text/javascript. This works for me on FIrefox document.querySelectorAll('script[type="text/javascript"]') Commented Aug 4, 2021 at 4:10

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.