WebView and Bridge

The WebView Engine and the JavaScript-to-Native Bridge

A Cordova 129 app is one native activity that fills the screen with a WebView. On Android, MainActivity extends CordovaActivity from CordovaLib, which creates the Android System WebView, the Chromium 4,389 engine Google updates through the Play Store (Chromium 133 on this book's emulator). Since cordova-android 10 (July 2021) the page is not opened from file://: a WebViewAssetLoader serves the www copy inside the APK as https://localhost/index.html, a real origin, so fetch(), cookies and storage behave as on the web.

The bridge is a Java object that CordovaLib hands to the page with Android's addJavascriptInterface(). It appears as window._cordovaNative, and its three @JavascriptInterface methods are the only doors from JavaScript into Java. Replies travel back as JavaScript that Java runs with evaluateJavascript():

The two directions of Cordova's Android bridge, from a plugin call to its callback
The two directions of Cordova's Android bridge, from a plugin call to its callback