コンテンツにジャンプ

はじめに

ターミナル画面
bun add @capgo/capacitor-webview-crash
bunx 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);
}

コピー

await WebViewCrash.clearPendingCrashInfo();

コピー

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

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

プラットフォームに関する注意
  • Androidは、 onRenderProcessGone、含む didCrashrendererPriorityAtExit プラットフォームが提供する場合にのみ取得します。
  • iOSは、 webViewWebContentProcessDidTerminate を含め、現在のアプリケーション状態を追加します。
  • Webでは、実際のレンダラーのクラッシュを検出できません。Web実装では、ローカルストレージのみを使用してシミュレートするためです。

型の参照

型の参照
export interface PendingCrashInfoResult {
/**
* Stored crash metadata, or `null` when no marker is pending.
*/
value: WebViewCrashInfo | null;
}
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;
}
export type WebViewCrashPlatform = 'android' | 'ios' | 'web';
export type WebViewCrashReason = 'renderProcessGone' | 'webContentProcessDidTerminate' | 'simulated';
export type WebViewCrashAppState = 'active' | 'inactive' | 'background' | 'unknown';

このページはプラグインから生成されています src/definitions.ts. upstream の API が変更されたときに、再度同步を実行してください。