Erste Schritte
Kopiere einen Setup-Prompt mit den Installationsschritten und dem vollständigen Markdown-Guide für dieses Plugin.
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.
Installieren
Abschnitt „Installation“Du kannst unser KI-gestütztes Setup nutzen, um das Plugin zu installieren. Füge die Capgo Skills mit dem folgenden Befehl deinem KI-Tool hinzu:
bunx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsNutze dann diesen Prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-webview-guardian` plugin in my project.Wenn du ein manuelles Setup bevorzugst, installiere das Plugin mit den folgenden Befehlen und befolge die plattformspezifischen Anweisungen unten:
bun add @capgo/capacitor-webview-guardianbunx cap syncImportieren
Abschnitt mit dem Titel „Import“import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';Quickstart
Abschnitt „Quick start“import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.startMonitoring();console.log(result);Beispiel: stopMonitoring
Abschnitt mit dem Titel „Beispiel: stopMonitoring“import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.stopMonitoring();console.log(result);Beispiel: getState
Abschnitt mit dem Titel „Beispiel: getState“import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.getState();console.log(result);Häufige Stolperfallen
Abschnitt „Häufige Fallstricke“- Listener: Handles beim Unmounten von Screens entfernen.
- Nativer Sync: ausführen
bunx cap syncnach Plugin-Upgrades. - Single Source of Truth: Vertrauen
src/definitions.tsim GitHub Repo.
API Übersicht
Abschnitt „API Übersicht“startMonitoring
Abschnitt mit dem Titel „startMonitoring“Beginnt mit der Überwachung von Foreground-Events und prüft automatisch den WebView-Status.
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.startMonitoring();console.log(result);stopMonitoring
Abschnitt mit dem Titel „stopMonitoring“Stoppt die automatische Foreground-Überwachung.
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.stopMonitoring();console.log(result);getState
Abschnitt „getState“Gibt den aktuellsten bekannten Monitoring-Status zurück.
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.getState();console.log(result);checkNow
Abschnitt „checkNow“Erzwingt sofort einen WebView-Health-Check.
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.checkNow();console.log(result);Typreferenz
Abschnitt mit dem Titel „Typreferenz“StartMonitoringOptions
Abschnitt „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
Abschnitt „GuardianState“export interface GuardianState { monitoring: boolean; reason: string; timestamp: string; lastHealthyAt?: string; lastRestartAt?: string; lastCrashAt?: string; pendingRestartReason?: string; error?: string;}CheckNowOptions
Abschnitt mit dem Titel “CheckNowOptions”export interface CheckNowOptions { /** * Text tag describing why a manual check is being requested. */ reason?: string;}CheckResult
Abschnitt mit dem Titel “CheckResult”export interface CheckResult { healthy: boolean; restarted: boolean; reason: string; timestamp: string; error?: string; pendingRestart?: boolean;}GuardianEvent
Abschnitt mit dem Titel “GuardianEvent”export type GuardianEvent = GuardianState;RestartStrategy
Abschnitt mit dem Titel “RestartStrategy”export type RestartStrategy = 'reload' | 'reloadFromOrigin' | 'customUrl';Source of Truth
Abschnitt mit dem Titel „Source of Truth“Diese Seite wird aus dem Plugin generiert src/definitions.ts. Führe den Sync erneut aus, wenn sich das öffentliche API upstream ändert.
Weiter geht's nach Getting Started
Abschnitt: „Weiter geht’s mit Getting Started“Wenn du es nutzt Erste Schritte , um natives Media- und Interface-Verhalten zu planen, verbinde es mit Verwendung von @capgo/capacitor-webview-guardian für die native Funktion bei der Nutzung von @capgo/capacitor-webview-guardian, @capgo/capacitor-live-activities verwenden für die native Funktion in „@capgo/capacitor-live-activities verwenden“, @capgo/capacitor-live-activities für die Implementierungsdetails in @capgo/capacitor-live-activities, Verwendung von @capgo/capacitor-video-player für die native Funktion in „@capgo/capacitor-video-player verwenden“, und @capgo/capacitor-video-player für das Implementierungsdetail in @capgo/capacitor-video-player.