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.
安装
标题为“安装”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
标题为“stopMonitoring”停止任何自动前台监控。
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
await WebviewGuardian.stopMonitoring();getState
标题为“getState”返回最新的已知监控状态。
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
await WebviewGuardian.getState();checkNow
立即检查强制 WebView 健康检查
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
await WebviewGuardian.checkNow();类型参考
类型参考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
守护状态export interface GuardianState { monitoring: boolean; reason: string; timestamp: string; lastHealthyAt?: string; lastRestartAt?: string; lastCrashAt?: string; pendingRestartReason?: string; error?: string;}CheckNowOptions
检查选项export interface CheckNowOptions { /** * Text tag describing why a manual check is being requested. */ reason?: string;}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 继续
名为“从 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中