开始
复制一个包含安装步骤和此插件的完整 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.
Install
安装您可以使用我们的AI辅助设置来安装插件。使用以下命令将Capgo技能添加到您的AI工具中。
bunx 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';快速入门
快速入门import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.startMonitoring();console.log(result);示例:停止监控
示例:停止监控import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.stopMonitoring();console.log(result);示例:getState
示例:getStateimport { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.getState();console.log(result);常见问题
常见问题- 监听器屏幕卸载时,移除句柄。
- 原生同步: run
bunx cap sync插件升级后。 - 数据源: trust
src/definitions.ts在 GitHub 仓库中。
API 简介
API 简介startMonitoring
开始监控开始监控前台事件并自动检查 WebView 健康。
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.startMonitoring();console.log(result);stopMonitoring
页面/区域: Capgo 营销网站。角色: UI 标签。见于: 页面 agents/[slug].astro。消息键 `agents_page_copy_label` (Agents Page Copy Label)。停止监控
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.stopMonitoring();console.log(result);getState
停止任何自动前台监控。获取状态
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.getState();console.log(result);checkNow
开始使用立即强制 WebView 健康检查。
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.checkNow();console.log(result);类型参考
类型参考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
GuardianEventexport type GuardianEvent = GuardianState;RestartStrategy
重启策略export type RestartStrategy = 'reload' | 'reloadFromOrigin' | 'customUrl';真实来源
真实来源本页面是由插件生成的 src/definitions.ts重新同步公共API时,重新运行上游
继续从开始
继续从开始如果您正在使用 开始使用 为native媒体和界面行为做好准备,连接它 使用@capgo/capacitor-webview-guardian 为@capgo/capacitor-webview-guardian中的native能力 使用@capgo/capacitor-live-activities 为@capgo/capacitor-live-activities中的native能力 @capgo/capacitor-live-activities 为@capgo/capacitor-live-activities中的实现细节 使用@capgo/capacitor-video-player 为使用@capgo/capacitor-video-player中的native能力 @capgo/capacitor-视频播放器 为@capgo/capacitor-video-player中的实现细节