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-guardian`
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-guardian/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.
安装
标题为“安装”您可以使用我们的 AI 助手来安装插件。将 Capgo 技能添加到您的 AI 工具中,使用以下命令:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-webview-guardian` plugin in my project.如果您更喜欢手动设置,请运行以下命令安装插件并按照以下平台特定的说明进行操作:
bun add @capgo/capacitor-webview-guardianbunx cap sync导入
标题:导入import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';API 概述
标题:API 概述startMonitoring
标题:startMonitoring开始观察前台事件并自动检查 WebView 健康状态。
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
await WebviewGuardian.startMonitoring();stopMonitoring
Section titled “stopMonitoring”停止任何自动前台监控。
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
await WebviewGuardian.stopMonitoring();getState
Section titled “getState”返回最新的已知监控状态。
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
await WebviewGuardian.getState();checkNow
Section titled “checkNow”立即强制 WebView 健康检查。
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
await WebviewGuardian.checkNow();StartMonitoringOptions
Section titled “StartMonitoringOptions”export interface StartMonitoringOptions { /** * Delay (in ms) before running a health check after the app re-enters the foreground. * Defaults to 600ms to let the bridge finish resuming. */ foregroundDebounceMs?: number;
/** * Script executed via `evaluateJavascript`/`evaluateJavaScript` to confirm the WebView is alive. * Defaults to `document.readyState`. */ pingScript?: string;
/** * Automatically reloads the WebView when a terminated render process is detected. * Disable to receive `webviewCrashed` events and restart manually. */ autoRestart?: boolean;
/** * Strategy used when restarting the WebView. Defaults to `reload`. */ restartStrategy?: RestartStrategy;
/** * Custom HTTPS/HTTP URL to load when `restartStrategy` is `customUrl`. */ customRestartUrl?: string;
/** * Emits verbose logging in the native layer when true. */ debug?: boolean;
/** * Whether an immediate health check should be executed right after enabling monitoring. * Defaults to `true`. */ runInitialCheck?: boolean;}GuardianState
名为“GuardianState”的部分export interface GuardianState { monitoring: boolean; reason: string; timestamp: string; lastHealthyAt?: string; lastRestartAt?: string; lastCrashAt?: string; pendingRestartReason?: string; error?: string;}CheckNowOptions
名为“CheckNowOptions”的部分export interface CheckNowOptions { /** * Text tag describing why a manual check is being requested. */ reason?: string;}CheckResult
名为“CheckResult”的部分export interface CheckResult { healthy: boolean; restarted: boolean; reason: string; timestamp: string; error?: string; pendingRestart?: boolean;}GuardianEvent
名为“GuardianEvent”的部分export type GuardianEvent = GuardianState;RestartStrategy
名为“RestartStrategy”的部分export type RestartStrategy = 'reload' | 'reloadFromOrigin' | 'customUrl';本页面由插件生成 src/definitions.ts. 当公共 API 上游更改时,请重新运行同步。
从 Getting Started 继续
Section titled “从 Getting Started 继续”如果您正在使用 Getting Started 来规划原生媒体和界面行为,连接它到 使用 @capgo/capacitor-webview-guardian 为原生能力在使用 @capgo/capacitor-webview-guardian 中 使用 @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 的实现细节