快速入门
复制包含安装步骤和该插件完整 Markdown 指南的配置 prompt。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-inappbrowser`
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/inappbrowser/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.
安装
“安装”章节你可以使用我们的 AI 辅助设置来安装插件。使用以下命令将 Capgo skills 添加到你的 AI 工具中:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下 prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-inappbrowser` plugin in my project.如果你更想手动设置,请运行以下命令安装插件,并按照下方各平台的说明操作:
npm install @capgo/capacitor-inappbrowsernpx cap sync导入
“导入”章节import { InAppBrowser } from '@capgo/capacitor-inappbrowser';快速入门:在托管 WebView 中实现托管结账
标题为“快速入门:在托管 WebView 中实现托管结账”import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.openWebView({ url: 'https://billing.example.com/checkout', toolbarType: 'navigation', title: 'Checkout',});
InAppBrowser.addListener('urlChangeEvent', (event) => { if (event.url.includes('/success')) { InAppBrowser.close(); }});使用 open() 或者当你想要使用 Safari View Controller 或 Chrome Custom Tabs,而不想嵌入完整的原生 WebView 栈时。
选择浏览器模式
标题为“选择浏览器模式”使用 open() 当你想要使用平台浏览器界面时:例如 Android 上的 Chrome Custom Tabs 以及 SFSafariViewController iOS 上的界面。使用 openWebView() 当你的应用需要控制原生 WebView 时:例如自定义尺寸、工具栏、应用消息传递、JavaScript 注入、下载、代理、弹窗、隐藏实例或 UI 层叠。
常见用例
“常见用例”章节在实时浏览器页面上显示 Ionic UI
标题为“在实时浏览器页面上显示 Ionic UI”使用 Capacitor 在托管的 WebView 后方打开受管 WebView, toBack。这样你的 Ionic UI 就可以在网页内容保持加载的同时,在页面上方进行渲染。通过使用 dispatchInputEvent() 将手势转发给浏览器,以便覆盖层能与页面进行交互。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
const { id } = await InAppBrowser.openWebView({ url: 'https://example.com/checkout', toBack: true, transparentBackground: true,});
await InAppBrowser.dispatchInputEvent({ id, type: 'click', x: 160, y: 420,});
await InAppBrowser.bringToFront({ id });在需要显示浏览器的位置,将相关的应用背景设置为透明。当浏览器位于应用后方时,除非你显式转发,否则原生手势仍由 Capacitor WebView 掌控。
构建部分屏幕浏览器或底部弹窗
标题为“构建部分屏幕浏览器或底部弹窗”的章节设置 height, width, x,以及 y 以便在原生浏览器周围保持 Capacitor 应用的部分可见。在 Android 和 iOS 上,浏览器框架外的触摸操作会透传到底层的 Capacitor WebView。
const bottomGap = 200;
const { id } = await InAppBrowser.openWebView({ url: 'https://example.com/offers', height: window.innerHeight - bottomGap, y: 0,});
await InAppBrowser.updateDimensions({ id, height: window.innerHeight, y: 0,});适用于微型浏览器、优惠面板、支持组件、基于浏览器的底部弹窗,或任何需要在 Web 内容之外保持原生应用控件可点击的流程。
让 Checkout、Auth 或 Support 会话保持私密
标题为“保护结账、认证或支持会话的隐私”的章节设置 persistWebViewData: false 用于受管理的 WebView,在平台支持的情况下,应避免持久化网站数据。在执行以下操作后调用 clearAllBrowsingData() 注销、切换账号、测试会话,或必须清除默认存储及已打开受管理 WebView 的流程。
const { id } = await InAppBrowser.openWebView({ url: 'https://example.com/login', persistWebViewData: false,});
await InAppBrowser.clearAllBrowsingData();await InAppBrowser.close({ id });在 Android 上,Cookie 使用系统 WebView 的 Cookie 存储,因此 clearAllBrowsingData() 是清理 Cookie 及其他共享浏览器数据的步骤。
随时准备好多个浏览器实例
标题为“保持多个浏览器实例就绪”的部分使用 hidden, hide(),以及 show() 用于预加载或保留多个受管理的 WebView,而无需将每个 WebView 都显示在屏幕上。隐藏的 WebView 仍可接收 executeScript(), postMessage(), setUrl(),以及关闭调用。
const first = await InAppBrowser.openWebView({ url: 'https://example.com/a', hidden: true });const second = await InAppBrowser.openWebView({ url: 'https://example.com/b', hidden: true });
await InAppBrowser.show({ id: first.id });await InAppBrowser.hide({ id: first.id });await InAppBrowser.show({ id: second.id });嵌入高级 Web App 流程
标题为“嵌入高级 Web App 工作流”的部分组合代理规则, handleDownloads, openBlankTargetInWebView, hiddenPopupWindow, enableGooglePaySupport, postMessage(),以及 executeScript() 适用于文档门户、上传流程、支付页面、客服台以及其他需要在不离开应用的情况下进行原生控制的嵌入式 Web 应用。
const { id } = await InAppBrowser.openWebView({ url: 'https://example.com/portal', handleDownloads: true, openBlankTargetInWebView: true, hiddenPopupWindow: true, outboundProxyRules: [ { urlRegex: '^https://example\\.com/api/', action: 'delegateToJs', }, ],});
await InAppBrowser.postMessage({ id, detail: { source: 'app', action: 'refresh' },});API 概览
章节标题:“API 概览”goBack
“goBack”章节如果可能,则在 WebView 历史记录中返回上一页
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.goBack();open
“open”章节在新窗口中以全屏方式打开 URL;Android 上使用 Chrome Custom Tabs,iOS 上使用 SFSafariViewController
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.open({} as OpenOptions);clearCookies
“clearCookies” 章节清除指定 URL 的 Cookie
当 id 被省略时,将应用于所有已打开的 webview。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.clearCookies({} as ClearCookieOptions);clearAllCookies
“clearAllCookies” 章节清除所有 Cookie
当 id 被省略时,将应用于所有已打开的 webview。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.clearAllCookies();clearCache
“clearCache” 章节清除缓存
当 id 被省略时,将应用于所有已打开的 webview。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.clearCache();clearAllBrowsingData
“clearAllBrowsingData” 章节清除默认存储区和已打开的受管 WebView 中的所有浏览数据,包括 Cookie、缓存、local storage、session storage、IndexedDB、表单数据,以及平台支持时的 HTTP 认证数据。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.clearAllBrowsingData();getCookies
“getCookies” 章节获取指定 URL 的 Cookie。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.getCookies({} as GetCookieOptions);close
“close” 章节关闭 webview。
当 id 省略时,关闭当前活动的 webview。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.close();hide
“hide” 章节隐藏 webview 而不关闭它。
使用 show() 重新显示。
当 id 若省略,则针对当前活跃的 webview。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.hide();show
“show” 章节显示之前隐藏的 webview。
当 id 若省略,则针对当前活跃的 webview。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.show();sendToBack
“sendToBack” 章节将原生浏览器移至 Capacitor 宿主 WebView 后方。当你的 Ionic UI 需要显示在实时浏览器页面之上时,请使用此功能。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.sendToBack({ id: 'webview-id', transparentBackground: true });bringToFront
“bringToFront” 章节将位于宿主 WebView 后方的浏览器移回最前端。当 id 若省略,则针对当前活跃的 webview。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.bringToFront({ id: 'webview-id' });dispatchInputEvent
“dispatchInputEvent” 章节向托管浏览器发送点击、触摸或滚动事件。坐标相对于浏览器视口,单位为 CSS 像素。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.dispatchInputEvent({ id: 'webview-id', type: 'click', x: 160, y: 420,});openWebView
“openWebView” 章节在带有工具栏的新 webview 中打开 URL,并提供增强功能,例如相机访问、文件访问、监听事件、注入 JavaScript、双向通信等。
JavaScript 接口: 使用此方法打开 webview 时,会自动注入一个提供以下功能的 JavaScript 接口:
window.mobileApp.close(): 从 JavaScript 关闭 webviewwindow.mobileApp.postMessage({detail: {message: "myMessage"}}): 从 webview 向 App 发送消息,detail 对象即为您要发送的数据window.mobileApp.takeScreenshot()何时allowScreenshotsFromWebPage为 true 时
不同平台的 Promise 触发时机不同 isPresentAfterPageLoad 已被使用。
Android 会在以下情况解析: { id } 对话框准备好控制后,而 iOS 会在 { id } 创建原生 webview 后立即解析。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.openWebView({} as OpenWebViewOptions);executeScript
标题为 “executeScript” 的章节将 JavaScript code 注入到 InAppBrowser 窗口中。
当 id 被省略时,将在所有打开的 webview 中执行。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.executeScript({} as { code: string; id?: string });postMessage
标题为 “postMessage” 的章节向 webview (in-app browser) 发送事件。在 webview 的 JavaScript 中,可以使用以下方式监听: window.addEventListener('messageFromNative', listenerFunc).
detail 是发送到 webview 的 payload。由于它需要跨越 Capacitor bridge,因此必须是 JSON 可序列化的。
当 id 若省略,则广播到所有已打开的 webview。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.postMessage({} as { detail: Record<string, any>; id?: string });takeScreenshot
“takeScreenshot” 章节将当前 webview 视口捕获为 PNG 截图。
当 id 若省略,则针对当前活跃的 webview。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.takeScreenshot();setUrl
“setUrl” 章节设置 webview 的 URL。
当 id 若省略,则针对当前活跃的 webview。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.setUrl({} as { url: string; id?: string });handleProxyRequest
“handleProxyRequest” 章节由以下项使用的内部方法: addProxyHandler() 将代理决策发送回 native 端。
转发原始 phase 回复手动 proxyRequest 监听器时。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.handleProxyRequest({} as { requestId: string; decision?: ProxyDecision | null; response?: ProxyResponse | null; webviewId?: string; phase?: 'outbound' | 'inbound'; });reload
标题为 “reload” 的章节重新加载当前网页。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.reload();updateDimensions
标题为 “updateDimensions” 的章节更新 webview 的尺寸。
允许在运行时更改 webview 的大小和位置。
当 id 若省略,则针对当前活跃的 webview。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.updateDimensions({} as DimensionOptions & { id?: string });setEnabledSafeTopMargin
标题为 “setEnabledSafeTopMargin” 的章节在运行时设置 webview 是否启用顶部安全边距。
当 id 若省略,则针对当前的 webview。
在 Web 端,此方法不执行任何操作,且会在不改变布局的情况下直接 resolve。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.setEnabledSafeTopMargin({} as { enabled: boolean; id?: string });setEnabledSafeBottomMargin
标题为 “setEnabledSafeBottomMargin” 的章节在运行时设置 webview 是否启用安全底部边距。
当 id 若省略,则针对当前的 webview。
在 Web 端,此方法不执行任何操作,且会在不改变布局的情况下直接 resolve。
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.setEnabledSafeBottomMargin({} as { enabled: boolean; id?: string });openSecureWindow
标题为 “openSecureWindow” 的章节打开一个用于 OAuth2 身份验证的安全窗口。 对于 Web 端,你需要在重定向页面中包含 code,以便使用 broadcast channel 将重定向 URL 发送给 App。 示例如下:
<html><head></head><body><script> const searchParams = new URLSearchParams(location.search) if (searchParams.has("code")) { new BroadcastChannel("my-channel-name").postMessage(location.href); window.close(); }</script></body></html>对于移动端,你需要一个可以唤起 App 的重定向 URI,示例如下: myapp://oauth_callback/
并确保已在 App 的 info.plist 中进行注册:
<key>CFBundleURLTypes</key><array> <dict> <key>CFBundleURLSchemes</key> <array> <string>myapp</string> </array> </dict></array>以及在 AndroidManifest.xml 文件中:
<activity> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:host="oauth_callback" android:scheme="myapp" /> </intent-filter></activity>import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
await InAppBrowser.openSecureWindow({} as OpenSecureWindowOptions);类型参考
“类型参考” 章节OpenOptions
标题为 “OpenOptions” 的部分export interface OpenOptions { /** * Target URL to load. * @since 0.1.0 */ url: string; /** * if true, the browser will be presented after the page is loaded, if false, the browser will be presented immediately. * @since 0.1.0 */ isPresentAfterPageLoad?: boolean; /** * if true the deeplink will not be opened, if false the deeplink will be opened when clicked on the link * @since 0.1.0 */ preventDeeplink?: boolean;
// --- Chrome Custom Tab customization (Android only, ignored on iOS) ---
/** * Toolbar background color in hex format (e.g., "#1A1A2E"). * Applied to both light and dark color schemes. * Also sets the navigation bar color to match. * **Android only** — ignored on iOS. * @since 8.2.0 */ toolbarColor?: string;
/** * Whether the URL bar should auto-hide when the user scrolls down. * The bar reappears on any upward scroll. * **Android only** — ignored on iOS. * @default false * @since 8.2.0 */ urlBarHidingEnabled?: boolean;
/** * Show the page's HTML <title> in the toolbar instead of the raw URL. * The true URL is still visible when the user taps the title area. * **Android only** — ignored on iOS. * @default false * @since 8.2.0 */ showTitle?: boolean;
/** * Replace the default "X" close icon with a back arrow. * Makes the Custom Tab feel like a native navigation push rather than a modal overlay. * **Android only** — ignored on iOS. * @default false * @since 8.2.0 */ showArrow?: boolean;
/** * Remove the share action from the overflow menu. * **Android only** — ignored on iOS. * @default false * @since 8.2.0 */ disableShare?: boolean;
/** * Hide the bookmark star icon in the overflow menu. * Uses an undocumented Chromium intent extra — may stop working on future Chrome updates. * **Android only** — ignored on iOS. * @default false * @since 8.2.0 */ disableBookmark?: boolean;
/** * Hide the download icon in the overflow menu. * Uses an undocumented Chromium intent extra — may stop working on future Chrome updates. * **Android only** — ignored on iOS. * @default false * @since 8.2.0 */ disableDownload?: boolean;}ClearCookieOptions
标题为 “ClearCookieOptions” 的部分export interface ClearCookieOptions { /** * Target webview id. * When omitted, applies to all open webviews. */ id?: string; url: string;}GetCookieOptions
标题为 “GetCookieOptions” 的部分export interface GetCookieOptions { url: string; includeHttpOnly?: boolean;}CloseWebviewOptions
标题为 “CloseWebviewOptions” 的部分export interface CloseWebviewOptions { /** * Target webview id to close. If omitted, closes the active webview. */ id?: string; /** * Whether the webview closing is animated or not, ios only * @default true */ isAnimated?: boolean;}LayerOptions
“LayerOptions” 章节export interface LayerOptions { /** * Target webview id. If omitted, targets the active webview. */ id?: string; /** * Makes the Capacitor host WebView transparent while this native webview is behind it. * * @default true */ transparentBackground?: boolean;}DispatchInputEventOptions
“DispatchInputEventOptions” 章节export type WebViewPointerInputEventType = 'click' | 'touchstart' | 'touchmove' | 'touchend' | 'touchcancel';export type WebViewInputEventType = WebViewPointerInputEventType | 'scroll';
export interface DispatchPointerInputEventOptions { id?: string; type: WebViewPointerInputEventType; x: number; y: number;}
export interface DispatchScrollInputEventOptions { id?: string; type: 'scroll'; x: number; y: number; deltaX: number; deltaY: number;}
export type DispatchInputEventOptions = DispatchPointerInputEventOptions | DispatchScrollInputEventOptions;OpenWebViewOptions
“OpenWebViewOptions” 章节export interface OpenWebViewOptions { /** * Target URL to load. * @since 0.1.0 * @example "https://capgo.app" */ url: string; /** * Headers to send with the request. * @since 0.1.0 * @example * headers: { * "Custom-Header": "test-value", * "Authorization": "Bearer test-token" * } * Test URL: https://www.whatismybrowser.com/detect/what-http-headers-is-my-browser-sending/ */ headers?: Headers; /** * Credentials to send with the request and all subsequent requests for the same host. * @since 6.1.0 * @example * credentials: { * username: "test-user", * password: "test-pass" * } * Test URL: https://www.whatismybrowser.com/detect/what-http-headers-is-my-browser-sending/ */ credentials?: Credentials; /** * HTTP method to use for the initial request. * * **Optional parameter - defaults to GET if not specified.** * Existing code that doesn't provide this parameter will continue to work unchanged with standard GET requests. * * When specified with 'POST', 'PUT', or 'PATCH' methods that support a body, * you can also provide a `body` parameter with the request payload. * * **Platform Notes:** * - iOS: Full support for all HTTP methods with headers * - Android: Custom headers may not be sent with POST/PUT/PATCH requests due to WebView limitations * * @since 8.2.0 * @default "GET" * @example * method: "POST", * body: JSON.stringify({ token: "auth-token", data: "value" }), * headers: { "Content-Type": "application/json" } */ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | string; /** * HTTP body to send with the request when using POST, PUT, or other methods that support a body. * Should be a string (use JSON.stringify for JSON data). * * **Optional parameter - only used when `method` is specified and supports a request body.** * Omitting this parameter (or using GET method) results in standard behavior without a request body. * * @since 8.2.0 * @example * method: "POST", * body: JSON.stringify({ username: "user", password: "pass" }), * headers: { "Content-Type": "application/json" } */ body?: string; /** * materialPicker: if true, uses Material Design theme for date and time pickers on Android. * This improves the appearance of HTML date inputs to use modern Material Design UI instead of the old style pickers. * @since 7.4.1 * @default false * @example * materialPicker: true * Test URL: https://show-picker.glitch.me/demo.html */ materialPicker?: boolean; /** * JavaScript Interface: * The webview automatically injects a JavaScript interface providing: * - `window.mobileApp.close()`: Closes the webview from JavaScript * - `window.mobileApp.postMessage(obj)`: Sends a message to the app (listen via "messageFromWebview" event) * - `window.mobileApp.hide()` / `window.mobileApp.show()` when allowWebViewJsVisibilityControl is true in CapacitorConfig * - `window.mobileApp.takeScreenshot()` when `allowScreenshotsFromWebPage` is true * * @example * // In your webpage loaded in the webview: * document.getElementById("closeBtn").addEventListener("click", () => { * window.mobileApp.close(); * }); * * // Send data to the app * window.mobileApp.postMessage({ action: "login", data: { user: "test" }}); * * @since 6.10.0 */ jsInterface?: never; // This property doesn't exist, it's just for documentation /** * Allows page JavaScript to call `window.mobileApp.takeScreenshot()`. * Disabled by default so only the host app can trigger native screenshots through the plugin API. * * @default false * @since 8.4.0 */ allowScreenshotsFromWebPage?: boolean; /** * Emits `consoleMessage` events for JavaScript `console.*` output coming from the managed page. * Useful when the webview stays hidden and you still need page-level diagnostics. * * @default false * @since 8.6.0 */ captureConsoleLogs?: boolean; /** * Controls whether the webview should persist website data such as cache, cookies, local storage, * IndexedDB, and session data. * * When false, iOS uses a non-persistent `WKWebsiteDataStore`. Android disables per-view cache and * DOM/database storage where the system WebView supports it. Android cookies use the shared * WebView cookie store, so call `clearAllBrowsingData()` to remove cookies and other global data. * * @default true * @since 8.6.36 */ persistWebViewData?: boolean; /** * Automatically handles downloads triggered inside the webview without requiring a custom JavaScript bridge. * * When enabled: * - Standard attachment responses are written to a temporary file. * - `blob:` downloads are also captured when the platform supports them. * - Previewable files reopen inside the in-app browser when possible. * - Other files are handed off to the native preview or viewer flow. * - `downloadCompleted` and `downloadFailed` events notify the host app about the saved file. * * @default false * @since 8.6.0 */ handleDownloads?: boolean; /** * Share options for the webview. When provided, shows a disclaimer dialog before sharing content. * This is useful for: * - Warning users about sharing sensitive information * - Getting user consent before sharing * - Explaining what will be shared * - Complying with privacy regulations * * Note: shareSubject is required when using shareDisclaimer * @since 0.1.0 * @example * shareDisclaimer: { * title: "Disclaimer", * message: "This is a test disclaimer", * confirmBtn: "Accept", * cancelBtn: "Decline" * } * Test URL: https://capgo.app */ shareDisclaimer?: DisclaimerOptions; /** * Toolbar type determines the appearance and behavior of the browser's toolbar * - "activity": Shows a simple toolbar with just a close button and share button * - "navigation": Shows a full navigation toolbar with back/forward buttons * - "blank": Shows no toolbar * - "": Default toolbar with close button * @since 0.1.0 * @default ToolBarType.DEFAULT * @example * toolbarType: ToolBarType.ACTIVITY, * title: "Activity Toolbar Test" * Test URL: https://capgo.app */ toolbarType?: ToolBarType; /** * Subject text for sharing. Required when using shareDisclaimer. * This text will be used as the subject line when sharing content. * @since 0.1.0 * @example "Share this page" */ shareSubject?: string; /** * Title of the browser * @since 0.1.0 * @default "New Window" * @example "Camera Test" */ title?: string; /** * Background color of the browser * @since 0.1.0 * @default BackgroundColor.BLACK */ backgroundColor?: BackgroundColor; /** * If true, enables native navigation gestures within the webview. * - Android: Native back button navigates within webview history * - iOS: Enables swipe left/right gestures for back/forward navigation * @default false (Android), true (iOS - enabled by default) * @example * activeNativeNavigationForWebview: true, * disableGoBackOnNativeApplication: true * Test URL: https://capgo.app */ activeNativeNavigationForWebview?: boolean; /** * Disable the possibility to go back on native application, * useful to force user to stay on the webview, Android only * @default false * @example * disableGoBackOnNativeApplication: true * Test URL: https://capgo.app */ disableGoBackOnNativeApplication?: boolean; /** * Open url in a new window fullscreen * isPresentAfterPageLoad: if true, the browser will be presented after the page is loaded, if false, the browser will be presented immediately. * Promise timing: on Android, `openWebView()` resolves with the webview id when the webview is ready to be controlled * (immediately for hidden/immediate presentation, after the first page load when `isPresentAfterPageLoad` is `true`). * On iOS, the promise resolves with the id as soon as the native webview is created, even if presentation is deferred. * @since 0.1.0 * @default false * @example * isPresentAfterPageLoad: true, * preShowScript: "await import('https://unpkg.com/darkreader@4.9.89/darkreader.js');\nDarkReader.enable({ brightness: 100, contrast: 90, sepia: 10 });" * Test URL: https://capgo.app */ isPresentAfterPageLoad?: boolean; /** * Whether the website in the webview is inspectable or not, ios only * @default false */ isInspectable?: boolean; /** * Whether the webview opening is animated or not, ios only * @default true */ isAnimated?: boolean; /** * Shows a reload button that reloads the web page * @since 1.0.15 * @default false * @example * showReloadButton: true * Test URL: https://capgo.app */ showReloadButton?: boolean; /** * CloseModal: if true a confirm will be displayed when user clicks on close button, if false the browser will be closed immediately. * @since 1.1.0 * @default false * @example * closeModal: true, * closeModalTitle: "Close Window", * closeModalDescription: "Are you sure you want to close?", * closeModalOk: "Yes, close", * closeModalCancel: "No, stay" * Test URL: https://capgo.app */ closeModal?: boolean; /** * CloseModalTitle: title of the confirm when user clicks on close button * @since 1.1.0 * @default "Close" */ closeModalTitle?: string; /** * CloseModalDescription: description of the confirm when user clicks on close button * @since 1.1.0 * @default "Are you sure you want to close this window?" */ closeModalDescription?: string; /** * CloseModalOk: text of the confirm button when user clicks on close button * @since 1.1.0 * @default "Close" */ closeModalOk?: string; /** * CloseModalCancel: text of the cancel button when user clicks on close button * @since 1.1.0 * @default "Cancel" */ closeModalCancel?: string; /** * closeModalURLPattern: a regex pattern to match against the current URL when the close button is pressed. * When provided along with closeModal: true, the close confirmation modal is only shown if the current URL matches this pattern. * If the current URL does not match, the browser closes immediately without showing the modal. * Requires closeModal to be true. * @since 7.2.0 * @example * closeModal: true, * closeModalURLPattern: ".*checkout.*" */ closeModalURLPattern?: string; /** * visibleTitle: if true the website title would be shown else shown empty * @since 1.2.5 * @default true */ visibleTitle?: boolean; /** * toolbarColor: color of the toolbar in hex format * @since 1.2.5 * @default "#ffffff" * @example * toolbarColor: "#FF5733" * Test URL: https://capgo.app */ toolbarColor?: string; /** * toolbarTextColor: color of the buttons and title in the toolbar in hex format * When set, it overrides the automatic light/dark mode detection for text color * @since 6.10.0 * @default calculated based on toolbarColor brightness * @example * toolbarTextColor: "#FFFFFF" * Test URL: https://capgo.app */ toolbarTextColor?: string; /** * showArrow: if true an arrow would be shown instead of cross for closing the window * @since 1.2.5 * @default false * @example * showArrow: true * Test URL: https://capgo.app */ showArrow?: boolean; /** * ignoreUntrustedSSLError: if true, the webview will ignore untrusted SSL errors allowing the user to view the website. * @since 6.1.0 * @default false */ ignoreUntrustedSSLError?: boolean; /** * preShowScript: if isPresentAfterPageLoad is true and this variable is set the plugin will inject a script before showing the browser. * This script will be run in an async context. The plugin will wait for the script to finish (max 10 seconds) * @since 6.6.0 * @example * preShowScript: "await import('https://unpkg.com/darkreader@4.9.89/darkreader.js');\nDarkReader.enable({ brightness: 100, contrast: 90, sepia: 10 });" * Test URL: https://capgo.app */ preShowScript?: string; /** * preShowScriptInjectionTime: controls when the preShowScript is injected. * - "documentStart": injects before any page JavaScript runs (good for polyfills like Firebase) * - "pageLoad": injects after page load (default, original behavior) * @since 7.26.0 * @default "pageLoad" * @example * preShowScriptInjectionTime: "documentStart" */ preShowScriptInjectionTime?: 'documentStart' | 'pageLoad'; /** * Proxy interception mode. * * - `true`: legacy blanket mode, delegates all HTTP/HTTPS requests to JavaScript. * - `string`: Android-only regex mode kept for backward compatibility. * * Prefer `outboundProxyRules` and `inboundProxyRules` for native-first matching. * * @since 6.9.0 */ proxyRequests?: boolean | string; /** * Native-first outbound proxy rules. * * @since 8.6.0 */ outboundProxyRules?: NativeProxyRule[]; /** * Native-first inbound proxy rules. * * @since 8.6.0 */ inboundProxyRules?: NativeProxyRule[]; /** * buttonNearDone allows for a creation of a custom button near the done/close button. * The button is only shown when toolbarType is not "activity", "navigation", or "blank". * * For Android: * - iconType must be "asset" * - icon path should be in the public folder (e.g. "monkey.svg") * - width and height are optional, defaults to 48dp * - button is positioned at the end of toolbar with 8dp margin * * For iOS: * - iconType can be "sf-symbol" or "asset" * - for sf-symbol, icon should be the symbol name * - for asset, icon should be the asset name * @since 6.7.0 * @example * buttonNearDone: { * ios: { * iconType: "sf-symbol", * icon: "star.fill" * }, * android: { * iconType: "asset", * icon: "public/monkey.svg", * width: 24, * height: 24 * } * } * Test URL: https://capgo.app */ buttonNearDone?: { ios: { iconType: 'sf-symbol' | 'asset'; icon: string; }; android: { iconType: 'asset' | 'vector'; icon: string; width?: number; height?: number; }; }; /** * Shows a native screenshot button near the done/close button. * The button is hidden by default and captures the current viewport when tapped. * This option uses the same toolbar slot as `buttonNearDone` and is therefore incompatible with it. * The button is only shown when toolbarType is not "activity", "navigation", or "blank". * * @default false * @since 8.4.0 */ showScreenshotButton?: boolean; /** * textZoom: sets the text zoom of the page in percent. * Allows users to increase or decrease the text size for better readability. * @since 7.6.0 * @default 100 * @example * textZoom: 120 * Test URL: https://capgo.app */ textZoom?: number; /** * enableZoom: enables pinch-to-zoom gestures in the Android WebView. * When true, built-in zoom controls are enabled and the zoom buttons are hidden. * **Android only** — ignored on iOS where zoom is enabled by default. * @since 8.5.0 * @default false * @example * enableZoom: true */ enableZoom?: boolean; /** * preventDeeplink: if true, the deeplink will not be opened, if false the deeplink will be opened when clicked on the link. on IOS each schema need to be added to info.plist file under LSApplicationQueriesSchemes when false to make it work. * @since 0.1.0 * @default false * @example * preventDeeplink: true * Test URL: https://aasa-tester.capgo.app/ */ preventDeeplink?: boolean;
/** * When true, HTTP and HTTPS links opened from `target="_blank"` anchors stay in the current webview instead of spawning a popup or opening in the system browser. * By default, blank-target HTTP(S) links stay inside the plugin as managed popups that share cookies with the opener; enabling this option keeps everything in the same tab. * Custom schemes such as `tel:` and `mailto:` and authorized app links still prefer their native handlers unless `preventDeeplink` is enabled. * * @since 8.5.6 * @default false * @example * openBlankTargetInWebView: true */ openBlankTargetInWebView?: boolean;
/** * List of base URLs whose hosts are treated as authorized App Links (Android) and Universal Links (iOS). * * - On both platforms, only HTTPS links whose host matches any entry in this list * will attempt to open via the corresponding native application. * - If the app is not installed or the system cannot handle the link, the URL * will continue loading inside the in-app browser. * - Matching is host-based (case-insensitive), ignoring the "www." prefix. * - When `preventDeeplink` is enabled, all external handling is blocked regardless of this list. * * @example * ```ts * ["https://example.com", "https://subdomain.app.io"] * ``` * * @since 7.12.0 * @default [] */ authorizedAppLinks?: string[];
/** * If true, the webView will not take the full height and will have a 20px margin at the bottom. * This creates a safe margin area outside the browser view. * @since 7.13.0 * @default false * @example * enabledSafeBottomMargin: true */ enabledSafeBottomMargin?: boolean;
/** * If false, the webView will extend behind the status bar for true full-screen immersive content. * When true (default), respects the safe area at the top of the screen. * Works independently of toolbarType - use for full-screen video players, games, or immersive web apps. * @since 8.2.0 * @default true * @example * enabledSafeTopMargin: false // Full screen, extends behind status bar */ enabledSafeTopMargin?: boolean;
/** * When true, applies the system status bar inset as the WebView top margin on Android. * Keeps the legacy 0px margin by default for apps that handle padding themselves. * @default false * @example * useTopInset: true */ useTopInset?: boolean;
/** * enableGooglePaySupport: if true, enables support for Google Pay popups and Payment Request API. * This fixes OR_BIBED_15 errors by allowing popup windows and configuring Cross-Origin-Opener-Policy. * Only enable this if you need Google Pay functionality as it allows popup windows. * * When enabled: * - Allows popup windows for Google Pay authentication * - Sets proper CORS headers for Payment Request API * - Enables multiple window support in WebView * - Configures secure context for payment processing * * @since 7.13.0 * @default false * @example * enableGooglePaySupport: true * Test URL: https://developers.google.com/pay/api/web/guides/tutorial */ enableGooglePaySupport?: boolean;
/** * Opens popup windows created by the page in hidden mode. * Hidden popup windows can still be controlled with `executeScript`, `postMessage`, `show`, and `close`. * Listen to `popupWindowOpened` to capture the popup id, then call `show({ id })` only if you want to reveal it. * * @default false * @since 8.6.0 * @example * hiddenPopupWindow: true */ hiddenPopupWindow?: boolean;
/** * blockedHosts: List of host patterns that should be blocked from loading in the InAppBrowser's internal navigations. * Any request inside WebView to a URL with a host matching any of these patterns will be blocked. * Supports wildcard patterns like: * - "*.example.com" to block all subdomains * - "www.example.*" to block wildcard domain extensions * * @since 7.17.0 * @default [] * @example * blockedHosts: ["*.tracking.com", "ads.example.com"] */ blockedHosts?: string[];
/** * Width of the webview in pixels. * If not set, webview will be fullscreen width. * @default undefined (fullscreen) * @example * width: 400 */ width?: number;
/** * Height of the webview in pixels. * If not set, webview will be fullscreen height. * @default undefined (fullscreen) * @example * height: 600 */ height?: number;
/** * X position of the webview in pixels from the left edge. * Only effective when width is set. * @default 0 * @example * x: 50 */ x?: number;
/** * Y position of the webview in pixels from the top edge. * Only effective when height is set. * @default 0 * @example * y: 100 */ y?: number;
/** * Places the native browser behind the Capacitor host WebView. * Make the app background transparent to reveal it, or rely on `transparentBackground` to clear the host WebView. * * @default false */ toBack?: boolean;
/** * When `toBack` is true, makes the Capacitor host WebView transparent so the native browser can be seen behind Ionic content. * Ignored when the browser is in front. * * @default true */ transparentBackground?: boolean;
/** * Disables the bounce (overscroll) effect on iOS WebView. * When enabled, prevents the rubber band scrolling effect when users scroll beyond content boundaries. * This is useful for: * - Creating a more native, app-like experience * - Preventing accidental overscroll states * - Avoiding issues when keyboard opens/closes * * Note: This option only affects iOS. Android does not have this bounce effect by default. * * @since 8.0.2 * @default false * @example * disableOverscroll: true */ disableOverscroll?: boolean;
/** * Opens the webview in hidden mode (not visible to user but fully functional). * When hidden, the webview loads and executes JavaScript but is not displayed. * All control methods (executeScript, postMessage, setUrl, etc.) work while hidden. * Use close() to clean up the hidden webview when done. * * @since 8.0.7 * @default false * @example * hidden: true */ hidden?: boolean;
/** * Controls how a hidden webview reports its visibility and size. * - AWARE: webview is aware it's hidden (dimensions may be zero). * - FAKE_VISIBLE: webview is hidden but reports fullscreen dimensions (uses alpha=0 to remain invisible). * * @default InvisibilityMode.AWARE * @example * invisibilityMode: InvisibilityMode.FAKE_VISIBLE */ invisibilityMode?: InvisibilityMode;}ScreenshotResult
“ScreenshotResult” 章节export interface ScreenshotResult { /** * Image format used for the screenshot. */ format: '.png'; /** * MIME type of the generated screenshot. */ mimeType: 'image/.png'; /** * Base64-encoded screenshot payload without the data URL prefix. */ base64: string; /** * Data URL for direct use in HTML img tags or uploads. */ dataUrl: string; /** * Screenshot width in pixels. */ width: number; /** * Screenshot height in pixels. */ height: number;}UrlChangeListener
“UrlChangeListener” 章节export type UrlChangeListener = (state: UrlEvent) => void;ButtonNearDoneEvent
“ButtonNearDoneEvent” 章节export interface ButtonNearDoneEvent { /** * Webview instance id. * * @since 8.6.36 */ id: string;}ButtonNearListener
“ButtonNearListener” 章节export type ButtonNearListener = (state: ButtonNearDoneEvent) => void;ConfirmBtnListener
“ConfirmBtnListener” 章节export type ConfirmBtnListener = (state: BtnEvent) => void;DownloadCompletedEvent
“DownloadCompletedEvent” 章节托管下载保存到本地后触发的事件。
export interface DownloadCompletedEvent { /** * Source webview instance id. */ id?: string; /** * Original URL that triggered the download when available. */ sourceUrl?: string; /** * Saved filename. */ fileName: string; /** * Resolved MIME type when available. */ mimeType?: string; /** * Absolute native filesystem path to the saved file. */ path: string; /** * `file://` URL pointing at the saved file. */ localUrl: string; /** * How native handled the downloaded file after saving it. */ handledBy: DownloadHandledBy;}DownloadFailedEvent
标题为“DownloadFailedEvent”的章节托管下载处理失败时触发的事件。
export interface DownloadFailedEvent { /** * Source webview instance id. */ id?: string; /** * Original URL that triggered the download when available. */ sourceUrl?: string; /** * Intended filename when known. */ fileName?: string; /** * Resolved MIME type when available. */ mimeType?: string; /** * Native error message. */ error: string;}PopupWindowEvent
“PopupWindowEvent” 章节当网页打开弹窗或新窗口时触发此事件。
export interface PopupWindowEvent { /** * Popup webview instance id. */ id: string; /** * Parent webview instance id. */ parentId?: string; /** * Requested popup URL when available. */ url?: string; /** * Whether the popup was presented immediately. */ visible: boolean;}单一事实来源
标题为“单一事实来源”的部分本页面由插件的 src/definitions.ts生成。当上游的公共 API 发生变化时,请重新运行 sync。
从入门指南继续
“从入门指南继续”章节如果你正在使用 快速入门 要规划 dashboard 和 API 操作,请将其连接到 使用 @capgo/capacitor-inappbrowser 关于使用 @capgo/capacitor-inappbrowser 时的原生能力, API 概览 关于 API Overview 中的实现细节, 简介 关于 Introduction 中的实现细节, API 密钥 有关 API Keys 的实现细节,以及 设备 有关 Devices 的实现细节。