指南
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-crashwebViewRestoredAfterCrash- 当恢复运行时,仍然待定的崩溃标记触发的监听事件。
示例用途
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);
}
全局参考
- GitHub https://github.com/Cap-go/capacitor-webview-crash/
- 文档: /docs/plugins/webview-crash/