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
bunx cap sync copies the plugin's native code into your native projects. Run it again after every plugin upgrade.
Import
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
API at a glance
| Method | Description |
|---|---|
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. |
Examples
startMonitoring()
Starts observing foreground events and automatically checks the WebView health.
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.startMonitoring();
console.log(result);
stopMonitoring()
Stops any automatic foreground monitoring.
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.stopMonitoring();
console.log(result);
getState()
Returns the latest known monitoring state.
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.getState();
console.log(result);
checkNow()
Forces a WebView health probe immediately.
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.checkNow();
console.log(result);
Listen to events
addListener returns a handle. Call handle.remove() when the screen unmounts.
Full reference
Keep going from Using @capgo/capacitor-webview-guardian
If you are using Using @capgo/capacitor-webview-guardian to plan native media and interface behavior, connect it with @capgo/capacitor-webview-guardian for the implementation detail in @capgo/capacitor-webview-guardian, Getting Started for the implementation detail in Getting Started, Using @capgo/capacitor-live-activities for the native capability in Using @capgo/capacitor-live-activities, @capgo/capacitor-live-activities for the implementation detail in @capgo/capacitor-live-activities, and Using @capgo/capacitor-video-player for the native capability in Using @capgo/capacitor-video-player.