コンテンツにスキップ

__CAPGO_KEEP_1__

ターミナル画面
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);
}

再起動のオプションを設定してください。 capacitor.config.ts JavaScriptランタイムがクラッシュしたりロードされていない場合でも、ネイティブのcodeの決定が残るようにしてください。

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;

常にオンのアプリで、ユーザーが同じWebViewを開いて日常的に使用する場合に使用してください。 restartIntervalMs キオスクスクリーン、コントロールルームのダッシュボード、倉庫のスキャナー、POS端末、車両のタブレット、デジタルサイネージなど。 restartCron 壁時計の再起動に使用してください。 0 3 * * * 03:00のデバイスローカルタイムゾーンでの毎日再起動を実行します。予定された再起動は、 reason: 'periodicRestart'、Androidはホストアクティビティを再作成し、iOSはCapacitor ブリッジビューを再構築するので、新しい WKWebView はネイティブcodeから作成されます。

選択できる間隔またはcronスケジュールは、製品が耐えることができるものです。 restartCron , *、リスト、範囲、ステップをサポートしています。両方のスケジュールを一度に設定しないでください:ネイティブの初期化は、 restartCron がセットされており、 restartIntervalMs0より大きい場合に致命的な構成エラーを投げます。再起動は、JavaScriptランタイムを新しく作成するので、積み重ねられたイベント、未保存のフォーム状態、現在のナビゲーション状態を保存する必要があります。aggressiveスケジュールを使用する前に。

呼び出し restartWebView() JavaScriptランタイムがネイティブのWebViewを予防的に置き換えることを決定したとき、たとえばメモリが重いワークフロー後にまたは長時間の無人セッションに入る前に:

await WebViewCrash.restartWebView();

__CAPGO_KEEP_0__の概要 reason: 'manualRestart', resolves the current call, then asks native code to create a fresh WebView. Android recreates the host activity. iOS rebuilds the Capacitor bridge view so a new WKWebView __CAPGO_KEEP_0__の概要

__CAPGO_KEEP_1__の概要 null clearPendingCrashInfo

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

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

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はCapacitor ブリッジビューを再構築します。
  • スケジュールされた再起動は reason: 'periodicRestart'を使用します。マニュアル再起動は reason: 'manualRestart'.
  • を使用します。

Webは実際のレンダラークラッシュを検出できません。Web実装はローカルストレージのみでシミュレートされた動作を実行します。

型参照

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 がアップストリームで変更されたときに、Sync を実行してください。

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