1.0.1 • Published 1 month ago

@jackobo/capacitor-webview v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

@jackobo/capacitor-webview

Capacitor plugin for Android and iOS WebView,
It opens an URL in a WebView.
It doesn't provide navigation support in the WebView. No back and forward buttons just a close button and a title in a toolbar.
You can control the toolbar background and text color.

Install

npm install @jackobo/capacitor-webview
npx cap sync

API

A capacitor plugin for opening a second WebView inside your app. Android and iOS only.

openWebView(...)

openWebView(options: IOpenWebViewOptions) => Promise<IOpenWebViewResponse>

Opens a new WebView using parameters specified in options. After opening the WebView the urlChanged event is also triggered for the initial URL provided in the options parameter. Method resolves when the WebView is closed either by the user or programatically by calling closeWebView. The response contains the URL that was in the WebView by the time of closing it.

ParamType
optionsIOpenWebViewOptions

Returns: Promise<IOpenWebViewResponse>

Since: 1.0.0


closeWebView()

closeWebView() => Promise<void>

Programmatically closes the WebView. The webViewClosed event is triggered also when calling this method.


addListener('urlChanged', ...)

addListener(eventName: 'urlChanged', handler: UrlChangedEventHandler) => Promise<PluginListenerHandle>

Subscribes to urlChanged event. This event is triggered when navigation occurs inside the WebView

ParamType
eventName'urlChanged'
handlerUrlChangedEventHandler

Returns: Promise<PluginListenerHandle>

Since: 1.0.0


addListener('webViewClosed', ...)

addListener(eventName: 'webViewClosed', handler: WebViewClosedEventHandler) => Promise<PluginListenerHandle>

Subscribes to webViewClosed event. This event is triggered when user closes the WebView or when the WebView is closed programmatically by calling closeWebView

ParamType
eventName'webViewClosed'
handlerWebViewClosedEventHandler

Returns: Promise<PluginListenerHandle>

Since: 1.0.0


removeAllListeners()

removeAllListeners() => Promise<void>

Removes all events subscriptions

Since: 1.0.0


Interfaces

IOpenWebViewResponse

The result of the openWebView method

PropTypeDescriptionSince
urlstringThe URL in the WebView by the time is closed1.0.0

IOpenWebViewOptions

PropTypeDescriptionDefaultSince
urlstringURL to load in the Webview1.0.0
headersRecord<string, string>Headers to be appended to the initial request. These are not used for subsequent navigation inside the WebView.1.0.0
enableDebugbooleanWhether to enable debug on the webview (iOS only)false1.0.0
toolbarIWebViewToolbarOptionsSpecify toolbar options. If null or undefined the toolbar will not be shown1.0.0
ignoreSslErrorsbooleanWhen set to true will disable the SSL errors (Android only) It should be used only for testing purpose in test environments if you encounter certificates issues Only SSL_UNTRUSTED errors are ignored when this property is set to truefalse1.0.0

IWebViewToolbarOptions

PropTypeDescriptionSince
titlestringThe text to appear in the toolbar1.0.0
backgroundColorstringBackground color of the toolbar in hex format1.0.0
colorstringThe color for the title text and for the X close button in hex format1.0.0

PluginListenerHandle

PropType
remove() => Promise<void>

UrlChangedEvent

Emit when the url changes in the Webview

PropTypeDescriptionSince
urlstringThe new URL in the WebView1.0.0

WebViewClosedEvent

Emit when the Webview is closed

PropTypeDescriptionSince
urlstringCurrent URL in the Webview by the time it is closed1.0.0

Type Aliases

Record

Construct a type with a set of properties K of type T

{

}

UrlChangedEventHandler

Handler for urlChanged event

(state: UrlChangedEvent): void

WebViewClosedEventHandler

Handler for webViewClosedEvent event

(state: WebViewClosedEvent): void

1.0.1

1 month ago

1.0.0

2 months ago