跳过内容

开始使用

安装

安装
终端窗口
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);
}

返回存储的本机崩溃标记,或 null 当没有待处理的崩溃时。

const pending = await WebViewCrash.getPendingCrashInfo();
if (pending.value) {
console.log(pending.value.platform, pending.value.reason);
}

清除存储的崩溃标记后,处理恢复完成。

await WebViewCrash.clearPendingCrashInfo();

simulateCrashRecovery

标题:模拟崩溃恢复

创建一个虚拟崩溃标记,以便 QA 和本地调试可以在不崩溃真实 WebView 的情况下演练恢复路径。

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

平台说明

平台说明
  • Android 从 onRenderProcessGone, 包括 didCrashrendererPriorityAtExit 当平台提供时。
  • iOS 从 webViewWebContentProcessDidTerminate 并添加当前应用程序状态(可用时)。
  • Web 不检测真实渲染器崩溃。Web 实现仅使用本地存储模拟行为。

类型引用

类型引用

PendingCrashInfoResult

待处理崩溃信息结果
export interface PendingCrashInfoResult {
/**
* Stored crash metadata, or `null` when no marker is pending.
*/
value: WebViewCrashInfo | null;
}

WebViewCrashInfo

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

WebViewCrashPlatform
export type WebViewCrashPlatform = 'android' | 'ios' | 'web';

WebViewCrashReason

WebViewCrashReason
export type WebViewCrashReason = 'renderProcessGone' | 'webContentProcessDidTerminate' | 'simulated';

WebViewCrashAppState

WebViewCrashAppState
export type WebViewCrashAppState = 'active' | 'inactive' | 'background' | 'unknown';

真实数据来源

本页面由插件生成

This page is generated from the plugin’s src/definitions.ts. 当 API 公共资源发生变化时,请重新同步。