开始使用
安装
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
标题:获取待处理的崩溃信息返回存储的本机崩溃标记,或 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
待处理崩溃信息结果export interface PendingCrashInfoResult { /** * Stored crash metadata, or `null` when no marker is pending. */ value: WebViewCrashInfo | null;}WebViewCrashInfo
WebViewCrashInfoexport 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
WebViewCrashPlatformexport type WebViewCrashPlatform = 'android' | 'ios' | 'web';WebViewCrashReason
WebViewCrashReasonexport type WebViewCrashReason = 'renderProcessGone' | 'webContentProcessDidTerminate' | 'simulated';WebViewCrashAppState
WebViewCrashAppStateexport type WebViewCrashAppState = 'active' | 'inactive' | 'background' | 'unknown';真实数据来源
本页面由插件生成This page is generated from the plugin’s src/definitions.ts. 当 API 公共资源发生变化时,请重新同步。