コンテンツにスキップ

Getting Started

GitHub

CapgoのAIアシストセットアップを使用してプラグインをインストールできます。AIツールにCapgoスキルを追加するには、以下のコマンドを実行してください。

ターミナル画面
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

次に、以下のプロンプトを使用してください。

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-webview-crash` plugin in my project.

Manualセットアップを使用する場合は、以下のコマンドを実行してプラグインをインストールし、以下のプラットフォーム固有の指示に従ってください。

ターミナル画面
npm install @capgo/capacitor-webview-crash
npx cap sync

インポート

「インポート」
import { WebViewCrash } from '@capgo/capacitor-webview-crash';
「推奨の復旧フロー」

アプリの起動時にリスナーを早く可能にし、ユーザーが画面を移動する前に復旧されたランタイムが反応できるようにしてください。

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);
}

ネイティブの自動再起動

「ネイティブの自動再起動」

再起動のオプションを設定 capacitor.config.ts JavaScriptランタイムがクラッシュしたりロードされていない場合でも、ネイティブのcodeに決定を残すようにしてください。

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;

使用 restartIntervalMs の場合 restartCron のアプリケーションでは、ユーザーがウェブビューを開いたままにし続けることができます: キオスクスクリーン、コントロールルームダッシュボード、倉庫スキャナーユニット、POS端末、車両タブレット、デジタルサイネージ。 0 3 * * * の場合 reason: 'periodicRestart', then Android recreates the host activity and iOS rebuilds the Capacitor bridge view so a new WKWebView is created from native code.

の場合 restartCron の場合 *の場合 restartCron の場合 restartIntervalMs の場合 0の場合

手動リスタート

手動リスタート

呼び出し restartWebView() HTMLテキストフラグメントから長いCapgo UI文字列 (親キー `appflow_migration_step2`)。ページ/エリア: Appflow比較/移行マーケティングコピー。役割: ウェブサイトコピー文。ページ: ionic-appflow.astro。Capgo製品/ブランドと開発者用語を完全に保持する。

await WebViewCrash.restartWebView();

クリップボードにコピー 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 現在の呼び出しを解決し、ネイティブの__CAPGO_KEEP_0__に新しいWebViewを作成するよう依頼します。Androidはホストアクティビティを再作成します。iOSは__CAPGO_KEEP_1__ブリッジビューを再構築し、新しい

APIの概要

APIの概要

getPendingCrashInfo

getPendingCrashInfo

保存されたネイティブのクラッシュまたはリスタートマーカーを返します、 null 何も待ち物がない場合。

const pending = await WebViewCrash.getPendingCrashInfo();
if (pending.value) {
console.log(pending.value.platform, pending.value.reason);
}

復旧処理が完了したら、保存されたマーカーを削除します。

await WebViewCrash.clearPendingCrashInfo();

QAやローカルデバッグのために、実際のWebViewをクラッシュさせずに復旧パスを実行できるように、偽のクラッシュマーカーを作成します。

const simulated = await WebViewCrash.simulateCrashRecovery();
console.log(simulated.value);

マニュアル再起動マーカーを保存し、native code に新しいWebViewを作成するように求めます。

await WebViewCrash.restartWebView();

プラットフォームに関する注意

Platform notes
  • Androidはクラッシュメタデータを onRenderProcessGone, didCrashrendererPriorityAtExit クラッシュメタデータを
  • クラッシュメタデータを含めて webViewWebContentProcessDidTerminate
  • Manual and scheduled restarts create a fresh WebView. Android recreates the host activity; iOS rebuilds the Capacitor bridge view.
  • アプリケーションの現在の状態を追加します。 reason: 'periodicRestart'再起動はWeb Viewを新しくします。Androidはホストアクティビティを再生成します; iOSは__CAPGO_KEEP_0__ ブリッジビューを再構築します。 reason: 'manualRestart'.
  • スケジュールされた再起動は

を使用します。手動の再起動は

「Type reference」のセクション
export interface PendingCrashInfoResult {
/**
* Stored crash or restart metadata, or `null` when no marker is pending.
*/
value: WebViewCrashInfo | null;
}
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;
}
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;
}
export type WebViewCrashPlatform = 'android' | 'ios' | 'web';
export type WebViewCrashReason =
| 'renderProcessGone'
| 'webContentProcessDidTerminate'
| 'periodicRestart'
| 'manualRestart'
| 'simulated';
export type WebViewCrashAppState = 'active' | 'inactive' | 'background' | 'unknown';

このページはプラグインの src/definitions.tsAPIがアップストリームで変更されたときに、パブリックの再同期を実行してください。

「Getting Started」から続けてください

「Getting Started」を使用して

「Getting Started」 ネイティブメディアとインターフェイスの動作を計画する場合、 「Using @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-webview-crash」を使用して 「Using @capgo/capacitor-webview-crash」 ネイティブ機能の「Using @capgo/capacitor-webview-crash」 Liveアクティビティの使用 (@capgo/capacitor-live-activities) native機能のためにLiveアクティビティの使用 (@capgo/capacitor-live-activities,) @capgo/capacitor-live-activities 実装詳細のためにLiveアクティビティ (@capgo/capacitor-live-activities,) Liveビデオプレーヤーの使用 (@capgo/capacitor-video-player) native機能のためにLiveビデオプレーヤーの使用 (@capgo/capacitor-video-player,) @capgo/capacitor-video-player 実装詳細のためにLiveビデオプレーヤー (@capgo/capacitor-video-player)