はじめに
インストール
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.
インストール
「インストール」のセクションbun add @capgo/capacitor-webview-crashbunx 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();});
const pending = await WebViewCrash.getPendingCrashInfo();// Note: the listener callback may have already cleared the pending marker.if (pending.value) { console.log('Pending crash marker', pending.value);}API の概要
API の概要getPendingCrashInfo
「getPendingCrashInfo」保存されたネイティブのクラッシュマーカーを取得します。何も保留されていない場合、 null コピー
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);プラットフォームに関する注意
プラットフォームに関する注意- Androidは、
onRenderProcessGone、含むdidCrash、rendererPriorityAtExitプラットフォームが提供する場合にのみ取得します。 - iOSは、
webViewWebContentProcessDidTerminateを含め、現在のアプリケーション状態を追加します。 - Webでは、実際のレンダラーのクラッシュを検出できません。Web実装では、ローカルストレージのみを使用してシミュレートするためです。
型の参照
型の参照PendingCrashInfoResult
「PendingCrashInfoResult」の参照export interface PendingCrashInfoResult { /** * Stored crash metadata, or `null` when no marker is pending. */ value: WebViewCrashInfo | null;}WebViewCrashInfo
「ウェブビュークラッシュ情報」のセクションexport interface WebViewCrashInfo { /** * Platform that detected and stored the crash marker. */ platform: WebViewCrashPlatform;
/** * Unix timestamp in milliseconds for when the crash marker was written. */ timestamp: number;
/** * ISO-8601 version of `timestamp`. */ timestampISO: string;
/** * Platform-specific reason for the crash marker. */ reason: WebViewCrashReason;
/** * Last known WebView URL when the crash 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
「ウェブビュークラッシュプラットフォーム」のセクションexport type WebViewCrashPlatform = 'android' | 'ios' | 'web';WebViewCrashReason
「ウェブビュークラッシュ理由」のセクションexport type WebViewCrashReason = 'renderProcessGone' | 'webContentProcessDidTerminate' | 'simulated';WebViewCrashAppState
「ウェブビュークラッシュアプリステート」のセクションexport type WebViewCrashAppState = 'active' | 'inactive' | 'background' | 'unknown';真実の源
「真実の源」のセクションこのページはプラグインから生成されています src/definitions.ts. upstream の API が変更されたときに、再度同步を実行してください。