浏览器API提供了在应用程序中打开浏览器并订阅浏览器事件的能力。
在iOS上,这使用 SFSafariViewController
并符合主要的OAuth服务应用程序内浏览器要求。
npm install @ieadpe/ecc-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: EccCapacitorBrowserOpenOptions) => Promise<void>
用指定的选项打开页面。
参数 | 类型 |
---|---|
options |
EccCapacitorBrowserOpenOptions |
since 1.0.0
close() => Promise<void>
Web & iOS only: 关闭一个打开的浏览器窗口。
在其他平台上无操作。
since 1.0.0
addListener(eventName: 'ieadpeBrowserFinished', listenerFunc: () => void) => Promise<PluginListenerHandle>
Android & iOS only: 监听浏览器完成事件。当浏览器被用户关闭时触发。
参数 | 类型 |
---|---|
eventName |
'ieadpeBrowserFinished' |
listenerFunc |
() => void |
Returns: Promise<PluginListenerHandle>
since 1.0.0
addListener(eventName: 'ieadpeBrowserPageLoaded', listenerFunc: () => void) => Promise<PluginListenerHandle>
Android & iOS only: 监听页面加载事件。仅在打开方法的URL完成加载时触发。对于后续页面加载不会调用。
参数 | 类型 |
---|---|
eventName |
'ieadpeBrowserPageLoaded' |
listenerFunc |
() => void |
Returns: Promise<PluginListenerHandle>
since 1.0.0
addListener(eventName: 'ieadpeBrowserLoggedIn', listenerFunc: (ieadpeDataReturn: EccCapacitorBrowserReturnOptions) => void) => Promise<PluginListenerHandle>
Android & iOS only: 监听url加载。在URL从服务器返回且来自重定向登录成功时触发。
参数 | 类型 |
---|---|
eventName |
'ieadpeBrowserLoggedIn' |
listenerFunc |
(ieadpeDataReturn: EccCapacitorBrowserReturnOptions) => void |
Returns: Promise<PluginListenerHandle>
since 1.0.0
removeAllListeners() => Promise<void>
移除此插件的全部原生监听器。
since 1.0.0
代表传递给 open
的选项。
属性 | 类型 | 描述 | since |
---|---|---|---|
url |
字符串 |
浏览器打开到的URL。 | 1.0.0 |
windowName |
字符串 |
Web仅:浏览器打开的目标(可选)。遵循window.open的target属性。默认为_blank。在其他平台上忽略。 | 1.0.0 |
toolbarColor |
字符串 |
将工具栏颜色设置为十六进制颜色的值。 | 1.0.0 |
presentationStyle |
'fullscreen' | 'popover' |
iOS仅:浏览器呈现方式。默认为全屏。在其他平台上忽略。 | 1.0.0 |
width |
数字 |
iOS仅:当在iPad上使用presentationStyle 'popover'时,浏览器的宽度。在其他平台上忽略。 | 4.0.0 |
height |
数字 |
iOS仅:当在iPad上使用presentationStyle 'popover'时,浏览器的高度。在其他平台上忽略。 | 4.0.0 |
属性 | 类型 |
---|---|
remove |
() => Promise<void> |
代表传递给 open
的选项。
属性 | 类型 | 描述 | since |
---|---|---|---|
url |
字符串 |
浏览器返回的URL。 | 1.0.0 |