benbot
benbot

Reputation: 1273

How to call WKWebView's evaluateJavaScript method

I'm trying to call a native WKWebView method, but nativescript keeps saying that the evaluateJavaScript function is undefined.

How should I try calling that function?

Here's the code I'm trying to run

console.log(nativeView.ios.evaluateJavaScript('document.URL', () => console.log('Hello, world')));

Upvotes: 0

Views: 544

Answers (1)

Manoj
Manoj

Reputation: 21908

evaluateJavaScriptCompletionHandler is the valid method name, it's documented here.

You may verify the callback for any errors before accessing the result.

webView.ios.evaluateJavaScriptCompletionHandler(jsStr,
            function (
                result,
                error
            ) {
                if (error) {
                    console.log("error...");
                    return;
                }
                console.log(result);
            });

If you still have issues, please share a Playground sample where the issue can be reproduced.

Upvotes: 1

Related Questions