__CAPGO_KEEP_1__
インストール手順とこのプラグインの全マークダウンガイドを含む設定用の質問をコピーする。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-webview-crash`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/webview-crash/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
インストール
「インストール」のセクションnpm install @capgo/capacitor-webview-crashnpx 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 がセットされており、 restartIntervalMs が 0より大きい場合に致命的な構成エラーを投げます。再起動は、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__の概要
API overview
Section titled “API overview”getPendingCrashInfo
クリップボードにコピー__CAPGO_KEEP_1__の概要 null clearPendingCrashInfo
const pending = await WebViewCrash.getPendingCrashInfo();if (pending.value) { console.log(pending.value.platform, pending.value.reason);}clearPendingCrashInfo
クリップボードにコピー復元処理が完了した後、保存されたマーカーをクリアします。
await WebViewCrash.clearPendingCrashInfo();simulateCrashRecovery
「シミュレートされたクラッシュ復旧」セクションQAやローカルデバッグのために、実際のWebViewをクラッシュさせずに復旧パスを実行できるように、偽のクラッシュマーカーを作成します。
const simulated = await WebViewCrash.simulateCrashRecovery();console.log(simulated.value);restartWebView
「WebViewを再起動する」セクションマニュアル再起動マーカーを保存し、ネイティブcodeに新しいWebViewを作成するように求めます。
await WebViewCrash.restartWebView();プラットフォームに関する注記
「プラットフォームに関する注記」セクション- Androidはクラッシュメタデータを
onRenderProcessGone、含みます。didCrashと、プラットフォームが提供する場合に。rendererPriorityAtExitiOSは - からクラッシュメタデータを取得し、
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;}WebViewCrashPluginConfig
WebViewCrashPluginConfigのセクション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;}WebViewCrashInfo
WebViewCrashInfoのセクション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;}WebViewCrashPlatform
WebViewCrashPlatformのセクションexport type WebViewCrashPlatform = 'android' | 'ios' | 'web';WebViewCrashReason
WebViewCrashReasonのセクションexport type WebViewCrashReason = | 'renderProcessGone' | 'webContentProcessDidTerminate' | 'periodicRestart' | 'manualRestart' | 'simulated';WebViewCrashAppState
WebViewCrashAppStateのセクションexport type WebViewCrashAppState = 'active' | 'inactive' | 'background' | 'unknown';真実の源
真実の源のセクションこのページはプラグインから生成されました。 src/definitions.ts再度、パブリック API がアップストリームで変更されたときに、Sync を実行してください。
Getting Started から続けてください。
Getting Started から続けてくださいというセクションのタイトルです。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の実装詳細について