Démarrage
Copiez un prompt de configuration avec les étapes d'installation et le guide Markdown complet pour ce plugin.
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.
Installer
Section intitulée « Installer »Vous pouvez utiliser notre configuration assistée par l'IA pour installer le plugin. Ajoutez les Capgo compétences à votre outil IA à l'aide de la commande suivante :
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsEnsuite, utilisez la prompt suivante :
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-webview-crash` plugin in my project.Si vous préférez la mise en place manuelle, installez le plugin en exécutant les commandes suivantes et suivez les instructions spécifiques à la plateforme ci-dessous :
npm install @capgo/capacitor-webview-crashnpx cap syncImporter
Section intitulée “Importer”import { WebViewCrash } from '@capgo/capacitor-webview-crash';Flux de récupération recommandé
Section intitulée “Flux de récupération recommandé”Attachez les écouteurs aussi tôt que possible dans le démarrage de votre application afin que le runtime récupéré puisse réagir avant que les utilisateurs continuent de naviguer :
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);}Redémarrage auto natif
Section intitulée “Redémarrage auto natif”Configure les options de redémarrage capacitor.config.ts afin que la décision reste dans le code natif même lorsque le runtime JavaScript a crashé ou n'a pas encore chargé :
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;Utiliser restartIntervalMs pour les applications toujours allumées où les utilisateurs peuvent conserver la même vue WebView ouverte pendant des jours : écrans de kiosque, tableaux de bord de contrôle, scanners de entrepôt, terminaux de caisse, tablettes de flotte et affichages numériques. Utiliser restartCron pour les redémarrages horloges comme 0 3 * * * pour un redémarrage quotidien à 03:00 dans la zone horaire locale du dispositif. Les redémarrages planifiés écrivent un marqueur de retard avec reason: 'periodicRestart'puis Android recrée l'activité de l'hôte et iOS rebranche la vue de pont Capacitor pour créer un nouveau WKWebView is created from native code.
supporte restartCron , listes, plages et étapes. N'configurez pas les deux plans à la fois : l'initialisation native lance une erreur de configuration mortelle lorsque *Configurez les options de redémarrage restartCron est défini et restartIntervalMs est supérieur à 0. Un redémarrage crée un runtime JavaScript frais, donc persistez les événements en file d'attente, l'état de formulaire non enregistré et l'état de navigation actuel avant d'utiliser des horaires agressifs.
Redémarrage natif manuel
Titre de la section « Redémarrage natif manuel »Appel restartWebView() Lorsque le runtime JavaScript actuel décide que la vue native WebView doit être remplacée de manière proactive, par exemple après un flux de travail lourd en mémoire ou avant d'entrer dans une session longue non surveillée :
await WebViewCrash.restartWebView();La méthode écrit un marqueur en attente avec 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 vue de pont __CAPGO_KEEP_1__ pour créer une nouvelle
API overview
Section intitulée « API résumé »getPendingCrashInfo
Section intitulée « getPendingCrashInfo »Renvoie le marqueur de crash ou de redémarrage natif stocké, ou null lorsqu'il n'y a rien en attente.
const pending = await WebViewCrash.getPendingCrashInfo();if (pending.value) { console.log(pending.value.platform, pending.value.reason);}clearPendingCrashInfo
Section intitulée « clearPendingCrashInfo »Supprime le marqueur stocké après que votre gestion de récupération est terminée.
await WebViewCrash.clearPendingCrashInfo();simulateCrashRecovery
Section intitulée « simulateCrashRecovery »Crée un marqueur de crash fictif afin que les équipes QA et les développeurs locaux puissent exercer le chemin de récupération sans faire crasher une vraie WebView.
const simulated = await WebViewCrash.simulateCrashRecovery();console.log(simulated.value);restartWebView
Section intitulée « redémarrerWebView »Stocke un marqueur de redémarrage manuel et demande au code natif de créer une WebView fraîche.
await WebViewCrash.restartWebView();Notes de plateforme
Section intitulée « Notes de plateforme »- Android stocke les métadonnées de crash à partir de
onRenderProcessGone, y comprisdidCrashetrendererPriorityAtExitlorsque la plateforme les fournit. - iOS stocke les métadonnées de crash à partir de
webViewWebContentProcessDidTerminateet ajoute l'état actuel de l'application lorsque disponible. - Les redémarrages manuels et planifiés créent une WebView fraîche. Android reçoit à nouveau l'activité hôte ; iOS reçoit à nouveau la vue de pont Capacitor.
- Les redémarrages planifiés utilisent
reason: 'periodicRestart'; redémarrages manuels utilisentreason: 'manualRestart'. - La mise en œuvre web ne détecte pas les crashes de rendu réels. La mise en œuvre web ne simule que le comportement avec le stockage local.
Type de référence
Section intitulée “Type de référence”PendingCrashInfoResult
Section intitulée “PendingCrashInfoResult”export interface PendingCrashInfoResult { /** * Stored crash or restart metadata, or `null` when no marker is pending. */ value: WebViewCrashInfo | null;}WebViewCrashPluginConfig
Section intitulée “WebViewCrashPluginConfig”export 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
Section intitulée “WebViewCrashInfo”export 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
Section intitulée “WebViewCrashPlatform”export type WebViewCrashPlatform = 'android' | 'ios' | 'web';WebViewCrashReason
Section intitulée « WebViewCrashReason »export type WebViewCrashReason = | 'renderProcessGone' | 'webContentProcessDidTerminate' | 'periodicRestart' | 'manualRestart' | 'simulated';WebViewCrashAppState
Section intitulée « WebViewCrashAppState »export type WebViewCrashAppState = 'active' | 'inactive' | 'background' | 'unknown';Source De Vérité
Section intitulée « Source De Vérité »Cette page est générée à partir du plugin’s src/definitions.tsRe-run la synchronisation lorsque le public API change en amont.
Continuez de Getting Started
Section intitulée « Continuez de Getting Started »Si vous utilisez Getting Started pour planifier le comportement de médias et d'interface native, connectez-le à Utiliser @capgo/capacitor-webview-crash pour la capacité native dans Utiliser @capgo/capacitor-webview-crash, Utiliser @capgo/capacitor-live-activities pour la capacité native dans Utiliser @capgo/capacitor-live-activities, @capgo/capacitor-live-activities pour le détail d'implémentation dans @capgo/capacitor-live-activities, Utiliser @capgo/capacitor-video-player pour la capacité native dans Utiliser @capgo/capacitor-video-player, et @capgo/capacitor-video-player pour le détail d'implémentation dans @capgo/capacitor-video-player.