Pembelajaran Dasar
Panduan setup dengan langkah instalasi dan panduan markdown lengkap untuk plugin ini yang dapat dicopy.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-webview-guardian`
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-guardian/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.
Install
Section titled “Install”Anda dapat menggunakan Setup Bantuan AI kami untuk menginstal plugin ini. Tambahkan Capgo kemampuan ke alat AI Anda menggunakan perintah berikut:
bunx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsMaka gunakan prompt berikut:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-webview-guardian` plugin in my project.Jika Anda lebih suka Setup Manual, instal plugin dengan menjalankan perintah-perintah berikut dan ikuti instruksi spesifik platform di bawah ini:
bun add @capgo/capacitor-webview-guardianbunx cap syncImport
Section titled “Import”import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';Mulai Cepat
Section titled “Quick start”import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.startMonitoring();console.log(result);Judul Bagian “Mulai Cepat”
Contoh: stopMonitoring (Contoh: Berhenti Mengawasi).import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.stopMonitoring();console.log(result);Contoh: getState
Judul Bagian “Contoh: getState”import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.getState();console.log(result);Kebiasaan Buruk Umum
Section titled “Common pitfalls”- ListenersHapus handle ketika layar tidak terdaftar.
- Sinkronisasi Nadi: run
bunx cap syncsetelah pembaruan plugin. - : setelah pengembangan plugin.: trust
src/definitions.tsdi dalam GitHub repo.
API Pengantar
Bab berjudul “API Pengantar”startMonitoring
Bab berjudul “startMonitoring”Mengawasi peristiwa latar depan dan secara otomatis memeriksa kesehatan WebView.
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.startMonitoring();console.log(result);Menghentikan pemantauan latar depan otomatis.
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.stopMonitoring();console.log(result);Mengembalikan status pemantauan terbaru yang diketahui.
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.getState();console.log(result);checkNow
Judul Bagian “checkNow”Menggunakan WebView probe kesehatan secara langsung.
import { WebviewGuardian } from '@capgo/capacitor-webview-guardian';
const result = await WebviewGuardian.checkNow();console.log(result);Referensi Tipe
Judul Bagian “Type Reference”StartMonitoringOptions
Judul Bagian “StartMonitoringOptions”export interface StartMonitoringOptions { /** * Delay (in ms) before running a health check after the app re-enters the foreground. * Defaults to 600ms to let the bridge finish resuming. */ foregroundDebounceMs?: number;
/** * Script executed via `evaluateJavascript`/`evaluateJavaScript` to confirm the WebView is alive. * Defaults to `document.readyState`. */ pingScript?: string;
/** * Automatically reloads the WebView when a terminated render process is detected. * Disable to receive `webviewCrashed` events and restart manually. */ autoRestart?: boolean;
/** * Strategy used when restarting the WebView. Defaults to `reload`. */ restartStrategy?: RestartStrategy;
/** * Custom HTTPS/HTTP URL to load when `restartStrategy` is `customUrl`. */ customRestartUrl?: string;
/** * Emits verbose logging in the native layer when true. */ debug?: boolean;
/** * Whether an immediate health check should be executed right after enabling monitoring. * Defaults to `true`. */ runInitialCheck?: boolean;}GuardianState
Judul Bagian “GuardianState”export interface GuardianState { monitoring: boolean; reason: string; timestamp: string; lastHealthyAt?: string; lastRestartAt?: string; lastCrashAt?: string; pendingRestartReason?: string; error?: string;}CheckNowOptions
Judul Bagian “CheckNowOptions”export interface CheckNowOptions { /** * Text tag describing why a manual check is being requested. */ reason?: string;}CheckResult
Judul Bagian “CheckResult”export interface CheckResult { healthy: boolean; restarted: boolean; reason: string; timestamp: string; error?: string; pendingRestart?: boolean;}GuardianEvent
Bab berjudul “GuardianEvent”export type GuardianEvent = GuardianState;RestartStrategy
Bab berjudul “RestartStrategy”export type RestartStrategy = 'reload' | 'reloadFromOrigin' | 'customUrl';Sumber Kebenaran
Bab berjudul “Sumber Kebenaran”Halaman ini dihasilkan dari plugin’s src/definitions.ts. Jalankan ulang sinkronisasi ketika publik API berubah di atas
Teruskan dari Getting Started
Bab berjudul “Teruskan dari Getting Started”Jika Anda menggunakan Mulai Berjalan untuk merencanakan perilaku media dan antarmuka native, hubungkannya dengan Menggunakan @capgo/capacitor-guardian-viewport untuk kemampuan native di Menggunakan @capgo/capacitor-guardian-viewport, Menggunakan @capgo/capacitor-aktivitas-hidup untuk kemampuan native di Menggunakan @capgo/capacitor-aktivitas-hidup, @capgo/capacitor-aktivitas-hidup untuk detail implementasi di @capgo/capacitor-aktivitas-hidup, Menggunakan @capgo/capacitor-pemain-video untuk kemampuan native di Menggunakan @capgo/capacitor-pemain-video, dan @capgo/capacitor-pemain-video untuk detail implementasi di @capgo/capacitor-pemain-video.