Démarrage
Copiez un prompt de configuration avec les étapes d'installation et la 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-pluginsUtilisez ensuite 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 configuration 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”Définir les options de redémarrage dans 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 chargé encore :
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 Web ouverte pendant des jours : écrans de kiosque, tableaux de bord de contrôle de salle, balayeurs de entrepôt, terminaux de caisse, tablettes de flotte et affichages numériques. restartCron Utiliser 0 3 * * * pour les redémarrages horloges telles que reason: 'periodicRestart', then Android recreates the host activity and iOS rebuilds the Capacitor bridge view so a new WKWebView , puis Android recrée l'activité de l'hôte et iOS reçoit à nouveau la vue de pont code afin qu'une nouvelle
Choisissez un intervalle ou un horaire planifié que votre produit peut supporter. restartCron __CAPGO_KEEP_0__ *soutient restartCron , des listes, des plages et des étapes. N'configurez pas les deux horaires d'un coup : l'initialisation native provoque une erreur de configuration mortelle lorsque restartIntervalMs est défini et 0est supérieur à
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 manuelSection intitulée “Redémarrage natif manuel” restartWebView() Appelez
await WebViewCrash.restartWebView();Copier dans le presse-papier : « « The method writes a pending marker with » » reason: 'manualRestart', résout l'appel actuel, puis demande à code de créer une nouvelle vue WebView. Android recrée l'activité hôte. iOS reçoit une nouvelle Capacitor vue de pont. WKWebView crée une nouvelle page au lieu de recharger la page actuelle.
API : vue d'ensemble
Section intitulée « API : vue d'ensemble »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 de débogage local puissent exercer le chemin de récupération sans faire planter une vraie WebView.
const simulated = await WebViewCrash.simulateCrashRecovery();console.log(simulated.value);restartWebView
Section intitulée « reinitialiserWebView »Stocke un marqueur de reinitialisation manuelle et demande au natif code de créer une WebView fraîche.
await WebViewCrash.restartWebView();Notes de plateforme
Section intitulée « Notes de plateforme »- Sur Android, les métadonnées de crash sont stockées à partir de
onRenderProcessGone, y comprisdidCrashetrendererPriorityAtExitlorsque la plateforme les fournit. - Sur iOS, les métadonnées de crash sont stockées à partir de
webViewWebContentProcessDidTerminateet ajoute l'état actuel de l'application lorsque celui-ci est disponible. - Redémarrages manuels et programmés créent une vue WebView fraîche. Android reçoit une nouvelle activité hôte ; iOS reçoit une nouvelle vue de pont Capacitor.
- Redémarrages programmés utilisent
reason: 'periodicRestart'; redémarrages manuels utilisentreason: 'manualRestart'. - La web ne détecte pas les crashs de rendu réels. La mise en œuvre web ne simule que le comportement avec le stockage local.
Référence de type
Section intitulée “Référence de type”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.tsRexécuter à nouveau la synchronisation lorsque le public API change en amont.
Continuez de l'étape de démarrage
Section intitulée « Continuez de l'onglet « Getting Started » »Si vous utilisez Getting Started pour planifier le comportement de médias natifs et d'interface, connectez-le à Utilisez @capgo/capacitor-webview-crash pour la capacité native dans Utilisez @capgo/capacitor-webview-crash, Utilisez @capgo/capacitor-live-activities pour la capacité native dans Utilisez @capgo/capacitor-live-activities, @capgo/capacitor-live-activities pour le détail d'implémentation dans @capgo/capacitor-live-activities, Utilisez @capgo/capacitor-video-player pour la capacité native dans Utilisez @capgo/capacitor-video-player, et @capgo/capacitor-player vidéo pour les détails d'implémentation dans @capgo/capacitor-player vidéo.