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 mit dem Titel „Installation“Du kannst unser KI-gestütztes Setup nutzen, um das Plugin zu installieren. Füge deinem KI-Tool die Capgo Skills mit folgendem Befehl hinzu:
bunx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsNutze anschließend 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 bevorziehst, 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 mit dem Titel „Quickstart“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 Fehlerquellen
Abschnitt mit dem Titel „Häufige Fehlerquellen“- Listener: Handles entfernen, wenn Screens unmounten.
- Native Sync: ausführen
bunx cap syncnach Plugin-Upgrades. - Single Source of Truth: vertraue
src/definitions.tsim GitHub Repo.
API Übersicht
Abschnitt mit dem Titel „API Übersicht“startMonitoring
Abschnitt „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 „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);Typ-Referenz
Abschnitt „Type Reference“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 „CheckNowOptions“export interface CheckNowOptions { /** * Text tag describing why a manual check is being requested. */ reason?: string;}CheckResult
Abschnitt „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- src/definitions.ts. Führe den Sync erneut aus, wenn sich der öffentliche API upstream ändert.
Weiter mit Getting Started
Abschnitt „Weiter mit Getting Started“Wenn Sie ... verwenden Erste Schritte um natives Medien- und Interface-Verhalten zu planen, verbinde es mit Verwendung von @capgo/capacitor-webview-guardian für die native Funktion in Verwendung 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 das Implementierungsdetail in @capgo/capacitor-live-activities, Verwendung von @capgo/capacitor-video-player für die native Funktion in Verwendung von @capgo/capacitor-video-player, und @capgo/capacitor-video-player für das Implementierungsdetail in @capgo/capacitor-video-player.