浏览器 API 提供了在应用内打开浏览器并订阅浏览器事件的能力。
在 iOS 上,这使用了 SFSafariViewController
并遵守领先 OAuth 服务在应用内浏览器的要求。
npm install @fontossolucoes/fontos-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('fontosBrowserFinished', ...)
addListener('fontosBrowserPageLoaded', ...)
removeAllListeners()
- 接口
open(options: OpenOptions) => Promise<void>
使用指定的选项打开页面。
参数 | 类型 |
---|---|
options |
OpenOptions |
自从 1.0.0
close() => Promise<void>
Web 与 iOS:关闭已打开的浏览器窗口。
在其他平台上无操作。
自从 1.0.0
addListener(eventName: 'fontosBrowserFinished', listenerFunc: () => void) => Promise<PluginListenerHandle>
Android 与 iOS:监听浏览器完成事件。它会在浏览器被用户关闭时触发。
参数 | 类型 |
---|---|
eventName |
'fontosBrowserFinished' |
listenerFunc |
() => void |
返回: Promise<PluginListenerHandle>
自从 1.0.0
addListener(eventName: 'fontosBrowserPageLoaded', listenerFunc: () => void) => Promise<PluginListenerHandle>
Android 与 iOS:监听页面加载事件。它只会在打开方法的 URL 加载完成时触发。它不会对任何后续页面加载调用。
参数 | 类型 |
---|---|
eventName |
'fontosBrowserPageLoaded' |
listenerFunc |
() => 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> |