跳到主要内容
版本:v2

Browser

浏览器API可以轻松地在应用内打开浏览器会话,用于显示外部网页内容、处理认证流程等场景。

在iOS平台上,该API使用SFSafariViewController实现,完全符合主流oAuth服务对应用内浏览器的要求。

import { Plugins } from '@capacitor/core';

const { Browser } = Plugins;

await Browser.open({ url: 'http://capacitorjs.com/' });

API

open(...)

open(options: BrowserOpenOptions) => Promise<void>

打开指定URL的页面

参数类型
options
BrowserOpenOptions

prefetch(...)

prefetch(options: BrowserPrefetchOptions) => Promise<void>

预加载指定URL以提升初始加载速度。

仅在Android平台有效,在iOS上无实际效果

参数类型
options
BrowserPrefetchOptions

close()

close() => Promise<void>

关闭已打开的浏览器窗口。仅在iOS和Web环境生效,其他平台无实际效果


addListener(...)

addListener(eventName: 'browserFinished', listenerFunc: (info: any) => void) => PluginListenerHandle
参数类型
eventName"browserFinished"
listenerFunc(info: any) => void

返回值:

PluginListenerHandle


addListener(...)

addListener(eventName: 'browserPageLoaded', listenerFunc: (info: any) => void) => PluginListenerHandle
参数类型
eventName"browserPageLoaded"
listenerFunc(info: any) => void

返回值:

PluginListenerHandle


removeAllListeners()

removeAllListeners() => void

移除该插件的所有原生监听器


Interfaces

BrowserOpenOptions

属性类型描述
urlstring要打开的浏览器URL地址
windowNamestring仅限Web端:可选浏览器打开目标。遵循window.open的target属性。默认为_blank
toolbarColorstring设置工具栏颜色的16进制色值
presentationStyle"fullscreen" | "popover"仅限iOS端:浏览器展示样式。默认为全屏(fullscreen)

BrowserPrefetchOptions

属性类型
urlsstring[]

PluginListenerHandle

属性类型
remove() => void