Using @capgo/capacitor-webview-guardian
Capacitor plugin to Detect when the WebView was killed in the background and relaunch it on foreground.
Install
bun add @capgo/capacitor-webview-guardian
bunx cap sync
What This Plugin Exposes
startMonitoring- Starts observing foreground events and automatically checks the WebView health.stopMonitoring- Stops any automatic foreground monitoring.getState- Returns the latest known monitoring state.checkNow- Forces a WebView health probe immediately.
Example Usage
startMonitoring
Starts observing foreground events and automatically checks the WebView health.
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
await WebviewGuardian.startMonitoring();
stopMonitoring
Stops any automatic foreground monitoring.
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
await WebviewGuardian.stopMonitoring();
getState
Returns the latest known monitoring state.
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
await WebviewGuardian.getState();
checkNow
Forces a WebView health probe immediately.
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
await WebviewGuardian.checkNow();
Full Reference
- GitHub: https://github.com/Cap-go/capacitor-webview-guardian/
- Docs: /docs/plugins/webview-guardian/