浏览器API提供了打开应用内浏览器和订阅浏览器事件的能力。
在iOS上,这使用了SFSafariViewController
,遵守了主要的OAuth服务应用内浏览器要求。
npm install @ieadpe/ieadpe-capacitor-browser
npx cap sync
此插件将使用以下项目变量(在您的应用的 variables.gradle
文件中定义)
androidxBrowserVersion
:版本androidx.browser:browser
(默认:1.7.0
)
import { Browser } from '@capacitor/browser';
const openCapacitorSite = async () => {
await Browser.open({ url: 'http://capacitorjs.com/' });
};
open(...)
close()
addListener('ieadpeBrowserFinished', ...)
addListener('ieadpeBrowserPageLoaded', ...)
addListener('ieadpeBrowserLoggedIn', ...)
removeAllListeners()
- 接口
open(options: IeadpeCapacitorBrowserOpenOptions) => Promise<void>
使用指定选项打开页面。
参数 | 类型 |
---|---|
options |
IeadpeCapacitorBrowserOpenOptions |
自从 1.0.0
close() => Promise<void>
Web 和 iOS:关闭打开的浏览器窗口。
在其他平台上不起作用。
自从 1.0.0
addListener(eventName: 'ieadpeBrowserFinished', listenerFunc: () => void) => Promise<PluginListenerHandle>
Android 和 iOS:监听浏览器完成事件。当用户关闭浏览器时触发。
参数 | 类型 |
---|---|
事件名称 |
'ieadpeBrowserFinished' |
监听函数 |
() => void |
返回值: Promise<PluginListenerHandle>
自从 1.0.0
addListener(eventName: 'ieadpeBrowserPageLoaded', listenerFunc: () => void) => Promise<PluginListenerHandle>
Android 和 iOS:监听页面加载事件。仅在打开方法的URL加载完成时触发。对于后续的页面加载不会触发。
参数 | 类型 |
---|---|
事件名称 |
'ieadpeBrowserPageLoaded' |
监听函数 |
() => void |
返回值: Promise<PluginListenerHandle>
自从 1.0.0
addListener(eventName: 'ieadpeBrowserLoggedIn', listenerFunc: (ieadpeDataReturn: IeadpeCapacitorBrowserReturnOptions) => void) => Promise<PluginListenerHandle>
Android 和 iOS:监听url加载事件。当来自服务器的URL是重定向登录成功时触发
参数 | 类型 |
---|---|
事件名称 |
'ieadpeBrowserLoggedIn' |
监听函数 |
(ieadpeDataReturn: IeadpeCapacitorBrowserReturnOptions) => void |
返回值: Promise<PluginListenerHandle>
自从 1.0.0
removeAllListeners() => Promise<void>
移除此插件的所有本地监听器。
自从 1.0.0
表示传递给 open
的选项。
属性 | 类型 | 描述 | 自从 |
---|---|---|---|
url |
string |
浏览器打开到的URL。 | 1.0.0 |
windowName |
string |
Web仅用:浏览器打开的可选目标。遵循 window.open 的 target 属性。默认为_blank。在其他平台上忽略。 | 1.0.0 |
toolbarColor |
string |
设置工具栏颜色的十六进制颜色。 | 1.0.0 |
presentationStyle |
'fullscreen' | 'popover' |
iOS仅用:浏览器的显示样式。默认为fullscreen。在其他平台上忽略。 | 1.0.0 |
width |
number |
iOS仅用:使用 presentationStyle 'popover' 在iPad上时浏览器的宽度。在其他平台上忽略。 | 4.0.0 |
height |
number |
iOS仅用:使用 presentationStyle 'popover' 在iPad上时浏览器的高度。在其他平台上忽略。 | 4.0.0 |
属性 | 类型 |
---|---|
remove |
() => Promise<void> |
表示传递给 open
的选项。
属性 | 类型 | 描述 | 自从 |
---|---|---|---|
url |
string |
浏览器返回时带有URL。 | 1.0.0 |