コンテンツにスキップ

始め方

GitHub

インストール

インストール

AI-Assisted セットアップを使用してプラグインをインストールできます。AI ツールに Capgo スキルを追加するには、以下のコマンドを実行してください。

ターミナル
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

次に、以下のプロンプトを使用してください。

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-webview-crash` plugin in my project.

Manual Setup を使用する場合は、以下のコマンドを実行してプラグインをインストールし、以下のプラットフォーム固有の指示に従ってください。

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

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

「ネイティブ再起動」セクション

Manual native restart

JavaScript実行環境がネイティブのWebViewを予防的に置き換えることを決定したときに呼び出される、たとえばメモリが多く消費されるワークフロー後に、または長時間の無人セッションに入る前に: restartWebView() クリップボードにコピー

await WebViewCrash.restartWebView();

現在の呼び出しを解決し、ネイティブの__CAPGO_KEEP_0__に新しいWebViewを作成するよう要求します。Androidはホストアクティビティを再作成します。iOSは__CAPGO_KEEP_1__ブリッジビューを再構築し、新しい 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__の概要

getPendingCrashInfo

セクション

保存されたネイティブのクラッシュまたは再起動マーカーを返します、または null 何も保留中でない場合。

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は__CAPGO_KEEP_0__ ブリッジビューを再構築します。
  • Manual and scheduled restarts create a fresh WebView. Android recreates the host activity; iOS rebuilds the Capacitor bridge view.
  • ; 手動再起動は reason: 'periodicRestart'Webは実際のレンダラークラッシュを検出しません。Web実装はローカルストレージのみでシミュレートする動作を提供します。 reason: 'manualRestart'.
  • 型参照

「型参照」のセクション

「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 から続けてください。

あなたが使用している場合 Getting Started ネイティブメディアとインターフェイスの動作を計画する場合、 @capgo/capacitor-webview-crash Using @capgo/capacitor-webview-crash Using @capgo/capacitor-live-activities Using @capgo/capacitor-live-activities @capgo/capacitor-live-activities @capgo/capacitor-live-activitiesの実装詳細 Using @capgo/capacitor-video-player Using @capgo/capacitor-video-playerのネイティブ機能 @capgo/capacitor-video-player @capgo/capacitor-video-playerの実装詳細