目录

What are the differences between runJavaScript and runJavaScriptExt of WebView? When are they called in the page lifecycle (such as onPageShow and onPageEnd)?

Both runJavaScript and runJavaScriptExt can execute JavaScript scripts asynchronously and return the result using callback or promise.

The difference is that the script execution result returned by runJavaScript can only be a string, while the type returned by runJavaScriptExt can be JsMessageType, including the string and array types.

Parameters of runJavaScript.

Name

Type

Mandatory

Description

script

string

Yes

JavaScript script.

callback

AsyncCallback<string>

Yes

Callback used to return the result. Returns null if the JavaScript script fails to be executed or no value is returned.

Parameters of runJavaScriptExt.

Name

Type

Mandatory

Description

script

string

Yes

JavaScript script.

callback

AsyncCallback<JsMessageExt>

Yes

Callback used to return the result.

In terms of invoking time, both of them need to be called after loadUrl is complete, for example, in onPageEnd.