Skip to content

Getting Started

ターミナル画面
npm install @capgo/capacitor-webview-crash
npx cap sync
import { WebViewCrash } from '@capgo/capacitor-webview-crash';

アプリ起動の早い段階でリスナを追加して、復元されたランタイムがユーザーがナビゲートを続ける前に反応できるようにします:

import { WebViewCrash } from '@capgo/capacitor-webview-crash';
await WebViewCrash.addListener('webViewRestoredAfterCrash', async (info) => {
console.log('Recovered after a WebView crash', info);
// Rehydrate critical state, reopen the correct screen, or prompt the user to retry.
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);
}

Set restart options in capacitor.config.ts so the decision stays in native code even when the JavaScript runtime has crashed or has not loaded yet:

import type { CapacitorConfig } from '@capacitor/cli';
import type { WebViewCrashPluginConfig } from '@capgo/capacitor-webview-crash';
const webViewCrash: WebViewCrashPluginConfig = {
// Enabled by default. Keep this on for long-running apps.
restartOnCrash: true,
// Use a 5-field cron schedule in the device local timezone.
// Do not combine restartCron with an active restartIntervalMs.
restartCron: '0 3 * * *',
// Optional delay before restarting after a crash.
restartAfterCrashDelayMs: 0,
};
const config: CapacitorConfig = {
plugins: {
WebViewCrash: webViewCrash,
},
};
export default config;

Use restartIntervalMs for always-on apps where users may keep the same WebView open for days: kiosk screens, control-room dashboards, warehouse scanners, POS terminals, fleet tablets, and digital signage. Use restartCron for wall-clock restarts such as 0 3 * * * __CAPGO_KEEP_0__ reason: 'periodicRestart', then Android recreates the host activity and iOS rebuilds the Capacitor bridge view so a new WKWebView is created from native code.

Androidはホストアクティビティを再構築し、iOSは__CAPGO_KEEP_0__ブリッジビューを再構築するので、新しい restartCron はnative __CAPGO_KEEP_0__から作成されます。 *間隔またはcronスケジュールを選択して、製品が耐えることができるものを選択してください。 restartCron is set and restartIntervalMs is greater than 0リスト、範囲、ステップをサポートしています。両方のスケジュールを同時に設定しないでください: native初期化はfatal configエラーを投げます。

再起動はJavaScriptランタイムを新しく作成するので、積み重ねられたイベント、未保存のフォーム状態、現在のナビゲーション状態を保存する必要があります。aggressiveスケジュールを使用する前に、 restartWebView() JavaScriptランタイムが、メモリが多く消費するワークフロー後に、または長時間の無人セッション前に、ネイティブのWebViewを予防的に置き換えることを決定した場合、たとえば:

await WebViewCrash.restartWebView();

このメソッドは、 reason: 'manualRestart'を解決し、ネイティブのcodeに新しいWebViewを作成するように求める。Androidはホストアクティビティを再構築します。iOSはCapacitorブリッジビューを再構築し、新しい WKWebView が作成されるのではなく、現在のページを再読み込みするのではなく。

APIの概要

APIの概要

getPendingCrashInfo

__CAPGO_KEEP_0__の概要

__CAPGO_KEEP_0__の概要 null __CAPGO_KEEP_0__の概要

const pending = await WebViewCrash.getPendingCrashInfo();
if (pending.value) {
console.log(pending.value.platform, pending.value.reason);
}

clearPendingCrashInfo

__CAPGO_KEEP_0__の概要

復元処理が完了したら、保存されたマーカーをクリアします。

await WebViewCrash.clearPendingCrashInfo();

QAやローカルデバッグで実際のWebViewをクラッシュさせずに復旧パスを実行できるように、偽のクラッシュマーカーを作成します。

const simulated = await WebViewCrash.simulateCrashRecovery();
console.log(simulated.value);

マニュアル再起動マーカーを保存し、ネイティブcodeに新しいWebViewを作成するように求めます。

await WebViewCrash.restartWebView();

プラットフォームに関する注記

「プラットフォームに関する注記」セクション
  • Androidはクラッシュメタデータを onRenderProcessGone、含みます。 didCrash と、プラットフォームが提供する場合。 rendererPriorityAtExit iOSはストアからクラッシュメタデータを取得し、
  • アプリケーションの現在の状態が利用可能な場合に、 webViewWebContentProcessDidTerminate 手動と予定された再起動は、WebViewを新しく作成します。Androidはホストアクティビティを再構築し、iOSは__CAPGO_KEEP_0__ブリッジビューを再構築します。
  • Manual and scheduled restarts create a fresh WebView. Android recreates the host activity; iOS rebuilds the Capacitor bridge view.
  • を使用します。手動の再起動は reason: 'periodicRestart'を使用します。 reason: 'manualRestart'.
  • Webは実際のレンダラーのクラッシュを検出しません。Web実装はローカルストレージのみで動作をシミュレートします。

型の参照

「型の参照」

PendingCrashInfoResult

「PendingCrashInfoResult」
export interface PendingCrashInfoResult {
/**
* Stored crash or restart metadata, or `null` when no marker is pending.
*/
value: WebViewCrashInfo | null;
}
export interface WebViewCrashPluginConfig {
/**
* Restart the WebView from native code when the renderer process dies.
*
* @default true
*/
restartOnCrash?: boolean;
/**
* Fixed native interval, in milliseconds, for proactively replacing long-running WebViews.
*
* Set to `0` to disable interval restarts. Do not combine an active interval
* with `restartCron`; native initialization fails fast when both schedules are configured.
*
* @default 0
*/
restartIntervalMs?: number;
/**
* Cron schedule for proactively replacing long-running WebViews.
*
* Uses standard 5-field cron syntax in the device local timezone:
* `minute hour day-of-month month day-of-week`.
*
* Examples:
* - `0 3 * * *` restarts every day at 03:00.
* - `0,30 * * * *` restarts every 30 minutes.
*
* Do not combine this with an active `restartIntervalMs`; native initialization
* fails fast when both schedules are configured.
*/
restartCron?: string;
/**
* Delay, in milliseconds, before restarting after a crash.
*
* @default 0
*/
restartAfterCrashDelayMs?: number;
}
export interface WebViewCrashInfo {
/**
* Platform that detected and stored the marker.
*/
platform: WebViewCrashPlatform;
/**
* Unix timestamp in milliseconds for when the marker was written.
*/
timestamp: number;
/**
* ISO-8601 version of `timestamp`.
*/
timestampISO: string;
/**
* Platform-specific reason for the crash or restart marker.
*/
reason: WebViewCrashReason;
/**
* Last known WebView URL when the marker was written.
*/
url?: string;
/**
* Android-only hint from `RenderProcessGoneDetail.didCrash()`.
*/
didCrash?: boolean;
/**
* Android-only renderer priority reported at exit.
*/
rendererPriorityAtExit?: number;
/**
* iOS-only application state captured when the WebView process died.
*/
appState?: WebViewCrashAppState;
}
export type WebViewCrashPlatform = 'android' | 'ios' | 'web';
export type WebViewCrashReason =
| 'renderProcessGone'
| 'webContentProcessDidTerminate'
| 'periodicRestart'
| 'manualRestart'
| 'simulated';
export type WebViewCrashAppState = 'active' | 'inactive' | 'background' | 'unknown';

このページはプラグインから生成されています。 src/definitions.ts再度の同期を実行するには、上流のAPIが公開された場合に実行してください。

Getting Startedから続けてください。

Getting Startedから続けてください。

Capgoを使用している場合 Getting Startedを使用して、ネイティブメディアとインターフェイスの動作を計画するには、 @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-webview-crashを使用してネイティブ機能と接続してください。 @capgo/capacitor-webview-crashのネイティブ機能と接続するには、@capgo/capacitor-webview-crashを使用してください。 @capgo/capacitor-live-activitiesを使用してネイティブ機能と接続するには、 @capgo/capacitor-live-activitiesのネイティブ機能と接続するには、@capgo/capacitor-live-activitiesを使用してください。 @capgo/capacitor-live-activities']} @capgo/capacitor-live-activities @capgo/capacitor-live-activitiesの実装詳細 @capgo/capacitor-video-playerを使用 @capgo/capacitor-video-playerのネイティブ機能を使用 @capgo/capacitor-video-player @capgo/capacitor-video-playerの実装詳細