Skip to main content
@capgo/capacitor-webview-guardian Auth & Security Open source

WebView Guardian Capacitor plugin

Detect when the WebView was killed in the background and relaunch it on foreground

Install

bun add @capgo/capacitor-webview-guardian bunx cap sync
npm, pnpm or yarn
  • npm install @capgo/capacitor-webview-guardian
  • pnpm add @capgo/capacitor-webview-guardian
  • yarn add @capgo/capacitor-webview-guardian

Guide

How to use WebView Guardian in Capacitor

Test on device

Download the Capgo app, then scan the QR code.

WebView Guardian plugin preview QR code

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.

FAQ

WebView Guardian plugin FAQ

How do I install the WebView Guardian plugin in a Capacitor app?

Run "bun add @capgo/capacitor-webview-guardian" (or "npm install @capgo/capacitor-webview-guardian"), then run "bunx cap sync" so the iOS and Android projects pick up the native code. Import it from "@capgo/capacitor-webview-guardian" in your app code.

Does @capgo/capacitor-webview-guardian work with React, Vue and Angular?

Yes. WebView Guardian is a Capacitor package, so it works with any web framework that runs inside Capacitor, including Ionic, React, Vue, Angular, Svelte and plain JavaScript.

Which Capacitor version does @capgo/capacitor-webview-guardian support?

Capgo plugins follow Capacitor's major version: use the plugin major version that matches your Capacitor major version (for example plugin v8 with Capacitor 8). The compatibility table in the GitHub README lists the maintained versions.

Is @capgo/capacitor-webview-guardian free and open source?

Yes. The source code is public on GitHub at https://github.com/Cap-go/capacitor-webview-guardian/ and the package is free to install from npm. Bug reports and pull requests are welcome.

Can I update code that uses WebView Guardian without an App Store review?

Installing or upgrading the plugin changes native code, so it needs a new store build. After that, JavaScript, HTML and CSS changes that call the plugin can ship instantly with Capgo live updates.

Ship WebView Guardian changes without waiting for app review

Once the plugin is in your store build, Capgo live updates push your JavaScript, HTML and CSS changes to users in minutes.

Start with Capgo