跳过主要内容
返回插件
@capgo/capacitor-webview-crash
教程
由 github.com/Cap-go

WebView Crash

检测恢复的WebView崩溃并告诉下一个JavaScript运行时发生了什么

指南

WebView崩溃教程

使用@capgo/capacitor-webview-crash

检测恢复的WebView崩溃并告诉下一个JavaScript运行时发生了什么。

安装

bun add @capgo/capacitor-webview-crash
bunx cap sync

此插件暴露的内容

  • getPendingCrashInfo - 返回存储的本机崩溃标记,或者 null - 清除存储的崩溃标记后,应用程序恢复其状态。
  • clearPendingCrashInfo - 创建一个虚拟崩溃标记,以便本地恢复流程可以进行测试。
  • simulateCrashRecovery 使用@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-webview-crash
  • webViewRestoredAfterCrash - 当恢复运行时,仍然待定的崩溃标记触发的监听事件。

示例用途

import { WebViewCrash } from '@capgo/capacitor-webview-crash';

await WebViewCrash.addListener('webViewRestoredAfterCrash', async (info) => {
  console.log('Recovered after a WebView crash', 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 marker', pending.value);
}

全局参考