Getting Started
复制一个设置提示,包含安装步骤和该插件的完整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共享数据集在构建时从 caniuse 数据中打包3- 不需要在默认流程中调用数据集 URL
- 复制到剪贴板
import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = { plugins: { WebviewVersionChecker: {}, },};
export default config;__CAPGO_KEEP_0__
Section titled “简单配置设置(显示原生提示)”import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = { plugins: { WebviewVersionChecker: { autoPromptOnOutdated: true, }, },};
export default config;高级阈值模式(自定义数据集)
Section titled “高级阈值模式(自定义数据集)”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
Section titled “高级使用JavaScript”import { 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)
__CAPGO_KEEP_0__
Android 提供商处理插件支持 Capacitor 在 Android 上使用的两种 WebView 提供商模型:
- Android 5-6 和 10+: Android System WebView (
com.google.android.webview) - Android 7-9: Google Chrome (
com.android.chrome)
继续从 Getting Started
继续从 Getting Started如果您正在使用 Getting Started 来规划原生媒体和界面行为,连接它与 使用 @capgo/capacitor-webview-version-checker 为原生能力在 Using @capgo/capacitor-webview-version-checker 中使用 使用 @capgo/capacitor-live-activities 为使用@capgo/capacitor-live-activities的原生能力 @capgo/capacitor-live-activities 为@capgo/capacitor-live-activities的实现细节 使用@capgo/capacitor-video-player 为使用@capgo/capacitor-video-player的原生能力, 和 @capgo/capacitor-video-player 为@capgo/capacitor-video-player的实现细节