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

WebView Crash Capacitor plugin

Restart crashed WebViews natively and recycle long-running WebViews on a fixed interval

Install

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

Guide

How to use WebView Crash in Capacitor

Test on device

Download the Capgo app, then scan the QR code.

WebView Crash plugin preview QR code

Using @capgo/capacitor-webview-crash

Detect recovered WebView crashes, restart dead WebViews natively, and recycle long-running WebViews on a fixed interval before memory pressure turns into an OOM.

Install

npm install @capgo/capacitor-webview-crash
npx cap sync

What This Plugin Exposes

  • Native restart after WebView crashes on iOS and Android.
  • Fixed-interval native WebView restart for kiosk, POS, signage, scanner, and dashboard apps that run for days.
  • restartWebView - Lets JavaScript request a fresh native WebView without doing a page reload.
  • WebViewCrashPluginConfig - Types plugins.WebViewCrash options in capacitor.config.ts.
  • getPendingCrashInfo - Returns the stored native crash or restart marker, or null when nothing is pending.
  • clearPendingCrashInfo - Clears the stored marker after your app has restored its state.
  • simulateCrashRecovery - Creates a fake crash marker so recovery flows can be tested locally.
  • webViewRestoredAfterCrash - Listener event fired when a crash marker is still pending in the recovered runtime.
  • webViewRestoredAfterRestart - Listener event fired when any native restart marker is still pending.

Example Usage

import { WebViewCrash } from '@capgo/capacitor-webview-crash';

await WebViewCrash.addListener('webViewRestoredAfterCrash', async (info) => {
  console.log('Recovered after a WebView crash', info);
  await WebViewCrash.clearPendingCrashInfo();
});

await WebViewCrash.addListener('webViewRestoredAfterRestart', async (info) => {
  console.log('Recovered after a native WebView restart', info);
  await WebViewCrash.clearPendingCrashInfo();
});

const pending = await WebViewCrash.getPendingCrashInfo();
// Note: the listener callback may have already cleared the pending marker.
if (pending.value) {
  console.log('Pending crash or restart marker', pending.value);
}

Native Auto Restart

Configure restart behavior in capacitor.config.ts so it keeps working when JavaScript is unavailable:

import type { CapacitorConfig } from '@capacitor/cli';
import type { WebViewCrashPluginConfig } from '@capgo/capacitor-webview-crash';

const webViewCrash: WebViewCrashPluginConfig = {
  restartOnCrash: true,
  restartCron: '0 3 * * *',
  restartAfterCrashDelayMs: 0,
};

const config: CapacitorConfig = {
  plugins: {
    WebViewCrash: webViewCrash,
  },
};

export default config;

Scheduled restarts write reason: 'periodicRestart'. Use restartIntervalMs for fixed intervals or restartCron for a 5-field cron schedule in the device local timezone, such as 0 3 * * * for a daily 03:00 restart. Do not configure both schedules at once: native initialization throws a fatal config error when restartCron is set and restartIntervalMs is greater than 0. Persist critical app state before using short schedules.

Manual Native Restart

Call restartWebView() when JavaScript decides the native WebView should be replaced proactively, for example after a memory-heavy workflow:

await WebViewCrash.restartWebView();

The method writes reason: 'manualRestart' and asks native code to create a fresh WebView. Android recreates the host activity. iOS rebuilds the Capacitor bridge view so a new WKWebView is created instead of reloading the current page.

Full Reference

Keep going from Using @capgo/capacitor-webview-crash

If you are using Using @capgo/capacitor-webview-crash to plan native media and interface behavior, connect it with @capgo/capacitor-webview-crash for the implementation detail in @capgo/capacitor-webview-crash, 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 Crash plugin FAQ

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

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

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

Yes. WebView Crash 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-crash 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-crash free and open source?

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

Can I update code that uses WebView Crash 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 Crash 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