跳过内容

开始入门

安装

安装
终端窗口
bun add @capgo/capacitor-webview-guardian
bunx cap sync

导入

导入
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';

API概述

API概述

开始监控前台事件并自动检查 WebView 健康状态。

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

stopMonitoring

标题:停止监控

停止任何自动前台监控。

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

返回最新的已知监控状态。

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

强制 WebView 健康检查。

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

标题:类型参考

__CAPGO_KEEP_0__

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

守护事件
export type GuardianEvent = GuardianState;

RestartStrategy

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

真实数据来源

真实数据来源

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

继续从 Getting Started

继续从 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的实现细节