跳过内容

开始

GitHub

您可以使用我们的 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-guardian
bunx cap sync
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';

startMonitoring

开始监控

开始监视前台事件并自动检查WebView的健康状况。

import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
await WebviewGuardian.startMonitoring();

stopMonitoring

停止监控

防止任何自动前台监控。

import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
await WebviewGuardian.stopMonitoring();

getState

getState

获取最新的已知监控状态。

import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
await WebviewGuardian.getState();

checkNow

checkNow

立即强制 WebView 健康检查。

import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
await WebviewGuardian.checkNow();

类型参考

类型参考

StartMonitoringOptions

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

检查结果
export interface CheckResult {
healthy: boolean;
restarted: boolean;
reason: string;
timestamp: string;
error?: string;
pendingRestart?: boolean;
}

GuardianEvent

GuardianEvent
export type GuardianEvent = GuardianState;

RestartStrategy

重启策略
export type RestartStrategy = 'reload' | 'reloadFromOrigin' | 'customUrl';

真实来源

真实来源

本页面由插件生成 src/definitions.ts重新同步时,重新运行公共API上游时发生变化。

如果您正在使用 开始使用 来规划原生媒体和界面行为,连接它到 使用@capgo/capacitor-webview-guardian 原生能力在使用@capgo/capacitor-webview-guardian 原生能力在使用@capgo/capacitor-live-activities 原生能力在使用@capgo/capacitor-live-activities @capgo/capacitor-实时活动 为 @capgo/capacitor-live-activities 的实现细节 使用 @capgo/capacitor-video-player 为原生能力在使用 @capgo/capacitor-video-player, 和 @capgo/capacitor-视频播放器 为 @capgo/capacitor-video-player 的实现细节