I hope to know some implementation details of WebView
's evaluateJavascript
. How does WebView execute the injected JavaScript code and return the result back to the Java part?
For example, suppose I use this API to execute jsCode
and then receive the result in its callback as value
.
webview.evaluateJavascript(jsCode, new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
}
});
Once the JavaScript side receives jsCode
, how does it execute jsCode
and return the result back to the callback of evaluateJavascript
? The following basic steps is what I guess:
Step 1: Receive jsCode
Step 2: Execute jsCode (e.g., result = eval(jsCode);) (using eval() is what I guess)
Step 3: Return result (e.g., return result;), which will be received by the callback of evaluateJavascript()
Does anyone know the how Android implements evaluateJavascript
? Or can you point out some sources (e.g., related Android source code) that I can study?