feat: add web view version check by preference AndroidMinimumWebViewVersion#1901
feat: add web view version check by preference AndroidMinimumWebViewVersion#1901GitToTheHub wants to merge 3 commits intomasterfrom
AndroidMinimumWebViewVersion#1901Conversation
…Version` - If preference `AndroidMinimumWebViewVersion` is set, it will check if the current installed web view suits the version. If not, an error message is shown and the app exists, after the user clicks on OK. - The strings can be internationalized by adding a `strings.xml` with appropriates strings to the appropriate `values` directory. - Generated-By: Claude Haiku 4.5, Visual Studio Code
- Generated-By: GPT-5.3-Codex, Visual Studio Code
- Generated-By: GPT-5.3-Codex, Visual Studio Code Copilot
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1901 +/- ##
=======================================
Coverage 61.43% 61.43%
=======================================
Files 24 24
Lines 4922 4922
=======================================
Hits 3024 3024
Misses 1898 1898 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
This is just my opinion, but I feel this might work better as a plugin rather than something included directly in the core library. I understand the concern where users might use modern JavaScript that may not be supported in older WebViews, and that users should be made aware of this. But, I would be interested in hearing what others think about where this should reside. For example, what if people begin asking for the ability to custom design the dialog so it could match their app's design? Or add various buttons that might do a certain function in those scenarios. I'm curious how large this could become to support and maintain within the core library. If it was a plugin, app developers can fork and manipulate easily the design if needed. |
|
We aren't suppose to assume the underlying webview implementation. It might not even be chrome-based or the system webview component. It could be someone's completely custom webview component for example. And I feel like this new preference assumes a particular webview implementation. So for that reason, like Erisu, I think this might be better off as a plugin rather than a core feature. |
Ok I didn't know, that the WebView could be changed. I could rename |
Platforms affected
Android
Motivation and Context
I often had the problem when deploying an Android app to an older emulator like Android version 7/8/9, where the WebView does not update in the emulator and using more recent JavaScript features like for e.g. optional chaining
?.which is available in Chrome 80, i got stuck in the splash screen and nothing happens. I also didn't see a JS alert, when I tried to catch errors. I tried to solve this in JS by checking the web view before, but I would have to check the web view version first and the had to load all scripts after, which is not a nice solution. Also, this feature could be made available more easy for others in this way.Description
AndroidMinimumWebViewVersionis set, it will check if the current installed web view suits the version. If not, an error message is shown and the app exists, after the user clicks on OK.strings.xmlwith appropriates strings to the appropriatevaluesdirectory.Overview of WebView Version Check Feature - Generated by Claude Haiku 4.5
Overview
This feature adds support for enforcing a minimum WebView version requirement in Cordova Android apps. If the installed WebView version is older than the specified minimum, a dialog will be shown to the user prompting them to update through the Google Play Store, and the app will close.
Usage
1. Add the Preference to config.xml
Add the
AndroidMinimumWebViewVersionpreference to yourconfig.xmlfile:2. Version Format
"80.0","90.0","100.0", etc."80.0.1234.56"- only the relevant parts will be compared3. What Happens
If a user's WebView version is too old:
4. Internationalization
The strings used in the dialog can be customized by overriding the string resources in your project's
res/values/directory:For other languages, create localized versions:
5. Examples
Example 1: Require WebView 80.0 or newer
Example 2: Require WebView 100.0 with specific patch
Example 3: No version requirement (feature disabled)
Technical Details
How it Works
WebViewCompat.getCurrentWebViewPackage()(API 26+) to get the installed WebView package, or falls back to querying thecom.google.android.webviewpackage directlyCordovaActivity.onCreate()after preferences are loaded but before any WebView content is loadedAlertDialogfor the warning messageError Handling
Supported Android Versions
This feature works on all supported Android versions. The WebView version checking uses Android 8+ optimized methods when available, with graceful fallbacks for older API levels.
Implementation Files Changed
API Details
The implementation includes four new private methods in
CordovaActivity:checkWebViewVersion()- Main method called from onCreategetWebViewVersion()- Retrieves the current WebView version stringisWebViewVersionSufficient()- Compares version stringsgetWebViewVersionTitle(),getWebViewVersionMessage(),getWebViewVersionButtonText()- Get localized strings with fallback defaultsString Customization
The dialog strings can be customized in three ways (in order of precedence):
Via app's string resources (highest priority):
webview_version_too_old_title,webview_version_too_old_message,webview_version_ok_buttonto your app'sres/values/strings.xmlVia template string resources:
cordova-android/templates/project/res/values/cdv_strings.xmlBuilt-in defaults (lowest priority):
Testing
<preference name="AndroidMinimumWebViewVersion" value="80.0" />Checklist
(platform)if this change only applies to one platform (e.g.(android))