Pembukaan
Copikan prompt pengaturan dengan langkah instalasi dan panduan markdown lengkap untuk plugin ini.
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.
Instalasi
Bab berjudul “Instalasi”Kamu bisa menggunakan Setup Bantuan AI kami untuk menginstal plugin. Tambahkan Capgo kemampuan ke alat AI kamu menggunakan perintah berikut:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsLalu gunakan prompt berikut:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-webview-crash` plugin in my project.Jika kamu lebih suka Setup Manual, instal plugin dengan menjalankan perintah-perintah berikut dan ikuti instruksi spesifik platform di bawah ini:
npm install @capgo/capacitor-webview-crashnpx cap syncImport
Judul Bagian “Import”import { WebViewCrash } from '@capgo/capacitor-webview-crash';Alur pemulihan yang disarankan
Judul Bagian “Alur pemulihan yang disarankan”Hubungkan pemangku hak sebagai awal mungkin dalam proses startup aplikasi Anda agar runtime yang dipulihkan dapat bereaksi sebelum pengguna melanjutkan navigasi:
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();});
await WebViewCrash.addListener('webViewRestoredAfterRestart', async (info) => { console.log('Recovered after a native WebView restart', 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 or restart marker', pending.value);}Auto restart native
Judul Bagian “Auto restart native”Setel opsi restart di capacitor.config.ts agar keputusan tetap berada di native code bahkan ketika runtime JavaScript telah mengalami crash atau belum dimuat:
import type { CapacitorConfig } from '@capacitor/cli';import type { WebViewCrashPluginConfig } from '@capgo/capacitor-webview-crash';
const webViewCrash: WebViewCrashPluginConfig = { // Enabled by default. Keep this on for long-running apps. restartOnCrash: true,
// Use a 5-field cron schedule in the device local timezone. // Do not combine restartCron with an active restartIntervalMs. restartCron: '0 3 * * *',
// Optional delay before restarting after a crash. restartAfterCrashDelayMs: 0,};
const config: CapacitorConfig = { plugins: { WebViewCrash: webViewCrash, },};
export default config;Gunakan restartIntervalMs untuk aplikasi selalu aktif di mana pengguna mungkin membuka WebView yang sama selama hari-hari: layar kiosk, dashboard ruang kontrol, scanner gudang, terminal kasir, tablet armada, dan tanda digital. restartCron untuk restart jam dinding seperti 0 3 * * * untuk restart harian pukul 03:00 di zona waktu lokal perangkat. Restart yang direncanakan menulis marker yang menunggu dengan reason: 'periodicRestart'kemudian Android merekonstruksi aktivitas host dan iOS membangun ulang jendela bridge Capacitor sehingga Capacitor baru dibuat dari Capacitor native. WKWebView is created from native code.
menggunakan restartCron daftar, rentang, dan langkah. Jangan konfigurasi kedua jadwal sekaligus: inisialisasi native melemparkan kesalahan konfigurasi fatal ketika *diatur dan restartCron lebih besar dari restartIntervalMs . Restart membuat runtime JavaScript yang segar, jadi simpan event yang antri, keadaan formulir yang belum disimpan, dan keadaan navigasi saat ini sebelum menggunakan jadwal agresif. 0Pilih interval atau jadwal cron yang produk Anda dapat menanggung.
Manual restart native
Judul bagian “Manual restart native”Panggil restartWebView() context: HTML fragment teks dari string Capgo UI yang lebih panjang (kunci induk `appflow_migration_step2`). Halaman/area: Perbandingan/migrasi Appflow / iklan pemasaran. Peran: Kalimat teks situs web. Dilihat di: halaman ionic-appflow.astro. Simpan Capgo produk/merek dan istilah pengembang secara tepat.
await WebViewCrash.restartWebView();Salin ke clipboard reason: 'manualRestart', resolves the current call, then asks native code to create a fresh WebView. Android recreates the host activity. iOS rebuilds the Capacitor bridge view so a new WKWebView , menyelesaikan panggilan saat ini, kemudian bertanya kepada native __CAPGO_KEEP_0__ untuk membuat WebView baru. Android merekreasi aktivitas host. iOS membangun kembali __CAPGO_KEEP_1__ jembatan view sehingga view baru
API overview
API ringkasangetPendingCrashInfo
Judul bagian “__CAPGO_KEEP_0__ ringkasan”Judul bagian “getPendingCrashInfo” null ketika tidak ada yang menunggu.
const pending = await WebViewCrash.getPendingCrashInfo();if (pending.value) { console.log(pending.value.platform, pending.value.reason);}clearPendingCrashInfo
Bab berjudul “clearPendingCrashInfo”Menghapus marker yang disimpan setelah proses pemulihan Anda selesai.
await WebViewCrash.clearPendingCrashInfo();simulateCrashRecovery
Bab berjudul “simulateCrashRecovery”Membuat marker kecelakaan palsu sehingga QA dan debugging lokal dapat menguji jalur pemulihan tanpa membuat WebView nyata mengalami kecelakaan.
const simulated = await WebViewCrash.simulateCrashRecovery();console.log(simulated.value);restartWebView
Bab berjudul “restartWebView”Menyimpan marker restart manual dan meminta native code untuk membuat WebView segar.
await WebViewCrash.restartWebView();Catatan platform
Catatan Platform- Android menyimpan metadata kecelakaan dari
onRenderProcessGone, termasukdidCrashdanrendererPriorityAtExitketika platform menyediakannya. - iOS menyimpan metadata kecelakaan dari
webViewWebContentProcessDidTerminatedan menambahkan keadaan aplikasi saat ini ketika tersedia. - Restart manual dan yang dijadwalkan membuat WebView yang segar. Android merekreasi aktivitas host; iOS membangun ulang jendela bridge Capacitor.
- Restart yang dijadwalkan menggunakan
reason: 'periodicRestart'; restart manual menggunakanreason: 'manualRestart'. - Web tidak mendeteksi kecelakaan renderer yang sebenarnya. Implementasi web hanya meniru perilaku dengan penyimpanan lokal.
Referensi Tipe
Panduan Referensi TipePendingCrashInfoResult
Panduan Referensi PendingCrashInfoResultexport interface PendingCrashInfoResult { /** * Stored crash or restart metadata, or `null` when no marker is pending. */ value: WebViewCrashInfo | null;}WebViewCrashPluginConfig
Panduan Referensi WebViewCrashPluginConfigexport interface WebViewCrashPluginConfig { /** * Restart the WebView from native code when the renderer process dies. * * @default true */ restartOnCrash?: boolean;
/** * Fixed native interval, in milliseconds, for proactively replacing long-running WebViews. * * Set to `0` to disable interval restarts. Do not combine an active interval * with `restartCron`; native initialization fails fast when both schedules are configured. * * @default 0 */ restartIntervalMs?: number;
/** * Cron schedule for proactively replacing long-running WebViews. * * Uses standard 5-field cron syntax in the device local timezone: * `minute hour day-of-month month day-of-week`. * * Examples: * - `0 3 * * *` restarts every day at 03:00. * - `0,30 * * * *` restarts every 30 minutes. * * Do not combine this with an active `restartIntervalMs`; native initialization * fails fast when both schedules are configured. */ restartCron?: string;
/** * Delay, in milliseconds, before restarting after a crash. * * @default 0 */ restartAfterCrashDelayMs?: number;}WebViewCrashInfo
Panduan Referensi WebViewCrashInfoexport interface WebViewCrashInfo { /** * Platform that detected and stored the marker. */ platform: WebViewCrashPlatform;
/** * Unix timestamp in milliseconds for when the marker was written. */ timestamp: number;
/** * ISO-8601 version of `timestamp`. */ timestampISO: string;
/** * Platform-specific reason for the crash or restart marker. */ reason: WebViewCrashReason;
/** * Last known WebView URL when the 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
Panduan Referensi WebViewCrashPlatformexport type WebViewCrashPlatform = 'android' | 'ios' | 'web';WebViewCrashReason
Panduan Referensi WebViewCrashReasonexport type WebViewCrashReason = | 'renderProcessGone' | 'webContentProcessDidTerminate' | 'periodicRestart' | 'manualRestart' | 'simulated';WebViewCrashAppState
Panduan Referensi WebViewCrashAppStateexport type WebViewCrashAppState = 'active' | 'inactive' | 'background' | 'unknown';Sumber Kebenaran
Bab berjudul “Sumber Kebenaran”Halaman ini dihasilkan dari plugin’s src/definitions.ts. Re-run sinkronisasi ketika API publik berubah di atas.
Teruskan dari Getting Started
Bab berjudul “Teruskan dari Getting Started”Jika Anda menggunakan Getting Started untuk merencanakan perilaku media asli dan antarmuka, hubungkannya dengan Menggunakan @capgo/capacitor-webview-crash untuk kemampuan asli di Menggunakan @capgo/capacitor-webview-crash, Untuk menggunakan @capgo/capacitor-live-aktivitas untuk kemampuan asli dalam Untuk menggunakan @capgo/capacitor-live-aktivitas @capgo/capacitor-live-aktivitas untuk detail implementasi dalam @capgo/capacitor-live-aktivitas Untuk menggunakan @capgo/capacitor-video-player untuk kemampuan asli dalam Untuk menggunakan @capgo/capacitor-video-player, dan @capgo/capacitor-video-player untuk detail implementasi dalam @capgo/capacitor-video-player