开始使用
复制一个包含安装步骤和本插件的完整Markdown指南的设置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-webview-version-checker`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/webview-version-checker/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
-
安装包
终端窗口 bun add @capgo/capacitor-webview-version-checker -
同步本机项目
终端窗口 bunx cap sync -
可选:添加插件配置 您可以使用默认值 (
WebviewVersionChecker: {}) 运行或自定义提示和阈值行为capacitor.config.ts.
默认行为(主要用例)
标题:默认行为(主要用例)默认情况下,这个插件使用一个浏览器列表兼容性规则:
minimumDeviceSharePercent默认值3- 共享数据集在构建时从 caniuse 数据中打包
- 不需要在默认流程中为默认行为调用运行时数据集 URL
import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = { plugins: { WebviewVersionChecker: {}, },};
export default config;仅配置设置(显示本机提示)
标题:仅配置设置(显示本机提示)import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = { plugins: { WebviewVersionChecker: { autoPromptOnOutdated: true, }, },};
export default config;高级阈值模式(自定义数据集)
标题:高级阈值模式(自定义数据集)import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = { plugins: { WebviewVersionChecker: { minimumDeviceSharePercent: 3, versionShareByMajor: { '137': 58.2, '136': 21.3, '135': 4.6, '134': 2.1, }, autoPromptOnOutdated: true, }, },};
export default config;如果您希望兼容性基于真实世界的分享而不是固定版本,请仅使用此选项。
minimumDeviceSharePercent: 3表示安装的主要版本必须代表您的数据集中的至少 3%。versionShareByMajor这是您的自定义映射:主要版本 => 百分比。- 如果您更喜欢远程数据,请使用
versionShareApiUrl其中之一:{ "versionShareByMajor": { "137": 54.2, "136": 23.8 } }{ "shareByMajor": { "137": 54.2, "136": 23.8 } }{ "versions": [{ "major": 137, "share": 54.2 }, { "version": "136.0.0.0", "percent": 23.8 }] }
高级使用 JavaScript
标题:高级使用 JavaScriptimport { WebviewVersionChecker } from '@capgo/capacitor-webview-version-checker';
await WebviewVersionChecker.addListener('webViewOutdated', (status) => { console.log('Outdated WebView detected', status);});
await WebviewVersionChecker.check({ minimumMajorVersion: 124, showPromptOnOutdated: true,});为什么要使用此插件而不是仅使用 Capacitor 配置
标题:为什么要使用此插件而不是仅使用 Capacitor 配置Capacitor 支持静态最小检查:
android: { minWebViewVersion: 124,},server: { errorPath: 'unsupported-webview.html',}该插件添加了运行时事件和原生提示用户界面,使用户仍然可以打开并使用应用程序,同时鼓励更新。
评估顺序:
- 设备共享阈值模式(+数据集),如果提供
minimumDeviceSharePercent最新版本模式( - 最小主要回退(
latestVersion/latestVersionApiUrl) - Android提供者处理
minimumMajorVersion)
标题为“Android提供者处理”
该插件支持__CAPGO_KEEP_0__在Android上使用的两种WebView提供者模型:The plugin supports both WebView provider models used by Capacitor on Android:
- Android 7-9:Google Chrome(
com.google.android.webview) - Android 7-9:Google Chrome(
com.android.chrome)