@capawesome/capacitor-in-app-browser 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapawesomeCapacitorInAppBrowser.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +690 -0
- package/android/build.gradle +60 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/InAppBrowser.java +242 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/InAppBrowserPlugin.java +289 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/CustomException.java +20 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/CustomExceptions.java +20 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/WebViewDialog.java +343 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/events/BrowserPageNavigationCompletedEvent.java +23 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/events/MessageReceivedEvent.java +23 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/options/ExecuteScriptOptions.java +29 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/options/GetCookiesOptions.java +29 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/options/OpenInExternalBrowserOptions.java +30 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/options/OpenInSystemBrowserOptions.java +74 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/options/OpenInWebViewOptions.java +112 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/options/PostMessageOptions.java +30 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/options/WebViewToolbarOptions.java +87 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/results/ExecuteScriptResult.java +25 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/results/GetCookiesResult.java +28 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/interfaces/EmptyCallback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +1173 -0
- package/dist/esm/definitions.d.ts +540 -0
- package/dist/esm/definitions.js +19 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +14 -0
- package/dist/esm/web.js +35 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +68 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +71 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Classes/Events/BrowserPageNavigationCompletedEvent.swift +16 -0
- package/ios/Plugin/Classes/Events/MessageReceivedEvent.swift +24 -0
- package/ios/Plugin/Classes/Options/ExecuteScriptOptions.swift +17 -0
- package/ios/Plugin/Classes/Options/GetCookiesOptions.swift +20 -0
- package/ios/Plugin/Classes/Options/OpenInExternalBrowserOptions.swift +20 -0
- package/ios/Plugin/Classes/Options/OpenInSystemBrowserOptions.swift +52 -0
- package/ios/Plugin/Classes/Options/OpenInWebViewOptions.swift +48 -0
- package/ios/Plugin/Classes/Options/PostMessageOptions.swift +17 -0
- package/ios/Plugin/Classes/Options/WebViewToolbarOptions.swift +37 -0
- package/ios/Plugin/Classes/Results/ExecuteScriptResult.swift +25 -0
- package/ios/Plugin/Classes/Results/GetCookiesResult.swift +20 -0
- package/ios/Plugin/Classes/WebViewController.swift +224 -0
- package/ios/Plugin/Enums/CustomError.swift +49 -0
- package/ios/Plugin/InAppBrowser.swift +194 -0
- package/ios/Plugin/InAppBrowserHelper.swift +49 -0
- package/ios/Plugin/InAppBrowserPlugin.swift +191 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Protocols/Result.swift +5 -0
- package/package.json +91 -0
package/README.md
ADDED
|
@@ -0,0 +1,690 @@
|
|
|
1
|
+
# @capawesome/capacitor-in-app-browser
|
|
2
|
+
|
|
3
|
+
Capacitor plugin to open URLs in the external browser, the system browser or an embedded web view.
|
|
4
|
+
|
|
5
|
+
<div class="capawesome-z29o10a">
|
|
6
|
+
<a href="https://cloud.capawesome.io/" target="_blank">
|
|
7
|
+
<img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.png?t=1" />
|
|
8
|
+
</a>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
We are proud to offer one of the most complete and feature-rich Capacitor plugins for in-app browsing. Here are some of the key features:
|
|
14
|
+
|
|
15
|
+
- 🌐 **Three browser modes**: Open URLs in the external browser, the system browser (Custom Tabs on Android, `SFSafariViewController` on iOS) or an embedded web view.
|
|
16
|
+
- 🧭 **Navigation events**: Get notified when the browser is closed, a page has been loaded or a navigation has been completed.
|
|
17
|
+
- 💉 **JavaScript execution**: Execute any JavaScript code in the embedded web view.
|
|
18
|
+
- 💬 **Messaging**: Exchange messages between your app and the web page in both directions.
|
|
19
|
+
- 🎨 **Toolbar theming**: Customize the toolbar color, title, close button and navigation buttons.
|
|
20
|
+
- 🍪 **Session control**: Clear the cache and session data, or use an isolated data store on iOS.
|
|
21
|
+
- 🎥 **Media permissions**: Camera and microphone permission requests from web pages are forwarded to the app.
|
|
22
|
+
- 📦 **CocoaPods & SPM**: Supports CocoaPods and Swift Package Manager for iOS.
|
|
23
|
+
- 🔁 **Up-to-date**: Always supports the latest Capacitor version.
|
|
24
|
+
|
|
25
|
+
Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
|
|
26
|
+
|
|
27
|
+
## Newsletter
|
|
28
|
+
|
|
29
|
+
Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
|
|
30
|
+
|
|
31
|
+
## Compatibility
|
|
32
|
+
|
|
33
|
+
| Plugin Version | Capacitor Version | Status |
|
|
34
|
+
| -------------- | ----------------- | -------------- |
|
|
35
|
+
| 0.x.x | >=8.x.x | Active support |
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
You can use our **AI-Assisted Setup** to install the plugin.
|
|
40
|
+
Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npx skills add capawesome-team/skills --skill capacitor-plugins
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Then use the following prompt:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-in-app-browser` plugin in my project.
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
If you prefer **Manual Setup**, install the plugin by running the following commands and follow the platform-specific instructions below:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npm install @capawesome/capacitor-in-app-browser
|
|
56
|
+
npx cap sync
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Android
|
|
60
|
+
|
|
61
|
+
#### Variables
|
|
62
|
+
|
|
63
|
+
This plugin will use the following project variables (defined in your app’s `variables.gradle` file):
|
|
64
|
+
|
|
65
|
+
- `$androidxBrowserVersion` version of `androidx.browser:browser` (default: `1.9.0`)
|
|
66
|
+
|
|
67
|
+
#### Permissions
|
|
68
|
+
|
|
69
|
+
If web pages opened in the embedded web view should be able to access the camera or microphone, the following elements must be added to your `AndroidManifest.xml` before or after the `application` tag:
|
|
70
|
+
|
|
71
|
+
```xml
|
|
72
|
+
<!-- Required if web pages should be able to access the camera. -->
|
|
73
|
+
<uses-permission android:name="android.permission.CAMERA" />
|
|
74
|
+
<!-- Required if web pages should be able to access the microphone. -->
|
|
75
|
+
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The permissions must also be granted before a web page requests access to the camera or microphone.
|
|
79
|
+
|
|
80
|
+
### iOS
|
|
81
|
+
|
|
82
|
+
#### Privacy Descriptions
|
|
83
|
+
|
|
84
|
+
If web pages opened in the embedded web view should be able to access the camera or microphone, the `NSCameraUsageDescription` and `NSMicrophoneUsageDescription` keys must be added to the `Info.plist` file of your app:
|
|
85
|
+
|
|
86
|
+
```xml
|
|
87
|
+
<key>NSCameraUsageDescription</key>
|
|
88
|
+
<string>The camera is used by websites opened in the in-app browser.</string>
|
|
89
|
+
<key>NSMicrophoneUsageDescription</key>
|
|
90
|
+
<string>The microphone is used by websites opened in the in-app browser.</string>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Configuration
|
|
94
|
+
|
|
95
|
+
No configuration required for this plugin.
|
|
96
|
+
|
|
97
|
+
## Usage
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { InAppBrowser } from '@capawesome/capacitor-in-app-browser';
|
|
101
|
+
|
|
102
|
+
const openInExternalBrowser = async () => {
|
|
103
|
+
await InAppBrowser.openInExternalBrowser({
|
|
104
|
+
url: 'https://capawesome.io',
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const openInSystemBrowser = async () => {
|
|
109
|
+
await InAppBrowser.openInSystemBrowser({
|
|
110
|
+
url: 'https://capawesome.io',
|
|
111
|
+
android: {
|
|
112
|
+
showTitle: true,
|
|
113
|
+
toolbarColor: '#008080',
|
|
114
|
+
},
|
|
115
|
+
ios: {
|
|
116
|
+
dismissButtonStyle: 'close',
|
|
117
|
+
toolbarColor: '#008080',
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const openInWebView = async () => {
|
|
123
|
+
await InAppBrowser.openInWebView({
|
|
124
|
+
url: 'https://capawesome.io',
|
|
125
|
+
toolbar: {
|
|
126
|
+
backgroundColor: '#008080',
|
|
127
|
+
color: '#FFFFFF',
|
|
128
|
+
showNavigationButtons: true,
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const close = async () => {
|
|
134
|
+
await InAppBrowser.close();
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const executeScript = async () => {
|
|
138
|
+
const { result } = await InAppBrowser.executeScript({
|
|
139
|
+
script: 'document.title',
|
|
140
|
+
});
|
|
141
|
+
return result;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const postMessage = async () => {
|
|
145
|
+
await InAppBrowser.postMessage({
|
|
146
|
+
data: { name: 'Capawesome' },
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const clearCache = async () => {
|
|
151
|
+
await InAppBrowser.clearCache();
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const clearSessionData = async () => {
|
|
155
|
+
await InAppBrowser.clearSessionData();
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const addListeners = async () => {
|
|
159
|
+
await InAppBrowser.addListener('browserClosed', () => {
|
|
160
|
+
console.log('Browser closed');
|
|
161
|
+
});
|
|
162
|
+
await InAppBrowser.addListener('browserPageLoaded', () => {
|
|
163
|
+
console.log('Browser page loaded');
|
|
164
|
+
});
|
|
165
|
+
await InAppBrowser.addListener('browserPageNavigationCompleted', event => {
|
|
166
|
+
console.log('Navigation completed', event.url);
|
|
167
|
+
});
|
|
168
|
+
await InAppBrowser.addListener('messageReceived', event => {
|
|
169
|
+
console.log('Message received', event.data);
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## API
|
|
175
|
+
|
|
176
|
+
<docgen-index>
|
|
177
|
+
|
|
178
|
+
* [`clearCache()`](#clearcache)
|
|
179
|
+
* [`clearSessionData()`](#clearsessiondata)
|
|
180
|
+
* [`close()`](#close)
|
|
181
|
+
* [`executeScript(...)`](#executescript)
|
|
182
|
+
* [`getCookies(...)`](#getcookies)
|
|
183
|
+
* [`openInExternalBrowser(...)`](#openinexternalbrowser)
|
|
184
|
+
* [`openInSystemBrowser(...)`](#openinsystembrowser)
|
|
185
|
+
* [`openInWebView(...)`](#openinwebview)
|
|
186
|
+
* [`postMessage(...)`](#postmessage)
|
|
187
|
+
* [`addListener('browserClosed', ...)`](#addlistenerbrowserclosed-)
|
|
188
|
+
* [`addListener('browserPageLoaded', ...)`](#addlistenerbrowserpageloaded-)
|
|
189
|
+
* [`addListener('browserPageNavigationCompleted', ...)`](#addlistenerbrowserpagenavigationcompleted-)
|
|
190
|
+
* [`addListener('messageReceived', ...)`](#addlistenermessagereceived-)
|
|
191
|
+
* [`removeAllListeners()`](#removealllisteners)
|
|
192
|
+
* [Interfaces](#interfaces)
|
|
193
|
+
* [Type Aliases](#type-aliases)
|
|
194
|
+
|
|
195
|
+
</docgen-index>
|
|
196
|
+
|
|
197
|
+
<docgen-api>
|
|
198
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
199
|
+
|
|
200
|
+
### clearCache()
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
clearCache() => Promise<void>
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Clear the cache of the web view.
|
|
207
|
+
|
|
208
|
+
Only available on Android and iOS.
|
|
209
|
+
|
|
210
|
+
**Since:** 0.1.0
|
|
211
|
+
|
|
212
|
+
--------------------
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
### clearSessionData()
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
clearSessionData() => Promise<void>
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Clear the session data (cookies and web storage) of the web view.
|
|
222
|
+
|
|
223
|
+
Only available on Android and iOS.
|
|
224
|
+
|
|
225
|
+
**Since:** 0.1.0
|
|
226
|
+
|
|
227
|
+
--------------------
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
### close()
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
close() => Promise<void>
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Close the currently open browser.
|
|
237
|
+
|
|
238
|
+
This closes browsers opened with `openInWebView(...)` or
|
|
239
|
+
`openInSystemBrowser(...)`.
|
|
240
|
+
|
|
241
|
+
Only available on Android and iOS.
|
|
242
|
+
|
|
243
|
+
**Since:** 0.1.0
|
|
244
|
+
|
|
245
|
+
--------------------
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
### executeScript(...)
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
executeScript(options: ExecuteScriptOptions) => Promise<ExecuteScriptResult>
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Execute a JavaScript script in the currently open web view.
|
|
255
|
+
|
|
256
|
+
This method is only available for browsers opened with
|
|
257
|
+
`openInWebView(...)`.
|
|
258
|
+
|
|
259
|
+
Only available on Android and iOS.
|
|
260
|
+
|
|
261
|
+
| Param | Type |
|
|
262
|
+
| ------------- | --------------------------------------------------------------------- |
|
|
263
|
+
| **`options`** | <code><a href="#executescriptoptions">ExecuteScriptOptions</a></code> |
|
|
264
|
+
|
|
265
|
+
**Returns:** <code>Promise<<a href="#executescriptresult">ExecuteScriptResult</a>></code>
|
|
266
|
+
|
|
267
|
+
**Since:** 0.1.0
|
|
268
|
+
|
|
269
|
+
--------------------
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
### getCookies(...)
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
getCookies(options: GetCookiesOptions) => Promise<GetCookiesResult>
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Get the cookies for a specific URL.
|
|
279
|
+
|
|
280
|
+
On iOS, only cookies from the shared data store are returned. Cookies from
|
|
281
|
+
a web view opened with `dataStore: 'isolated'` are not included.
|
|
282
|
+
|
|
283
|
+
Only available on Android and iOS.
|
|
284
|
+
|
|
285
|
+
| Param | Type |
|
|
286
|
+
| ------------- | --------------------------------------------------------------- |
|
|
287
|
+
| **`options`** | <code><a href="#getcookiesoptions">GetCookiesOptions</a></code> |
|
|
288
|
+
|
|
289
|
+
**Returns:** <code>Promise<<a href="#getcookiesresult">GetCookiesResult</a>></code>
|
|
290
|
+
|
|
291
|
+
**Since:** 0.1.0
|
|
292
|
+
|
|
293
|
+
--------------------
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
### openInExternalBrowser(...)
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
openInExternalBrowser(options: OpenInExternalBrowserOptions) => Promise<void>
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Open a URL in the default browser app of the device.
|
|
303
|
+
|
|
304
|
+
| Param | Type |
|
|
305
|
+
| ------------- | ------------------------------------------------------------------------------------- |
|
|
306
|
+
| **`options`** | <code><a href="#openinexternalbrowseroptions">OpenInExternalBrowserOptions</a></code> |
|
|
307
|
+
|
|
308
|
+
**Since:** 0.1.0
|
|
309
|
+
|
|
310
|
+
--------------------
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
### openInSystemBrowser(...)
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
openInSystemBrowser(options: OpenInSystemBrowserOptions) => Promise<void>
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Open a URL in the system browser (Custom Tabs on Android,
|
|
320
|
+
`SFSafariViewController` on iOS).
|
|
321
|
+
|
|
322
|
+
Only available on Android and iOS.
|
|
323
|
+
|
|
324
|
+
| Param | Type |
|
|
325
|
+
| ------------- | --------------------------------------------------------------------------------- |
|
|
326
|
+
| **`options`** | <code><a href="#openinsystembrowseroptions">OpenInSystemBrowserOptions</a></code> |
|
|
327
|
+
|
|
328
|
+
**Since:** 0.1.0
|
|
329
|
+
|
|
330
|
+
--------------------
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
### openInWebView(...)
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
openInWebView(options: OpenInWebViewOptions) => Promise<void>
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
Open a URL in an embedded web view with a native toolbar.
|
|
340
|
+
|
|
341
|
+
Only available on Android and iOS.
|
|
342
|
+
|
|
343
|
+
| Param | Type |
|
|
344
|
+
| ------------- | --------------------------------------------------------------------- |
|
|
345
|
+
| **`options`** | <code><a href="#openinwebviewoptions">OpenInWebViewOptions</a></code> |
|
|
346
|
+
|
|
347
|
+
**Since:** 0.1.0
|
|
348
|
+
|
|
349
|
+
--------------------
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
### postMessage(...)
|
|
353
|
+
|
|
354
|
+
```typescript
|
|
355
|
+
postMessage(options: PostMessageOptions) => Promise<void>
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
Post a message to the currently open web view.
|
|
359
|
+
|
|
360
|
+
The web page receives the message by listening for the
|
|
361
|
+
`capacitorInAppBrowserMessage` window event. The message data is
|
|
362
|
+
available in the `detail` property of the event.
|
|
363
|
+
|
|
364
|
+
This method is only available for browsers opened with
|
|
365
|
+
`openInWebView(...)`.
|
|
366
|
+
|
|
367
|
+
Only available on Android and iOS.
|
|
368
|
+
|
|
369
|
+
| Param | Type |
|
|
370
|
+
| ------------- | ----------------------------------------------------------------- |
|
|
371
|
+
| **`options`** | <code><a href="#postmessageoptions">PostMessageOptions</a></code> |
|
|
372
|
+
|
|
373
|
+
**Since:** 0.1.0
|
|
374
|
+
|
|
375
|
+
--------------------
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
### addListener('browserClosed', ...)
|
|
379
|
+
|
|
380
|
+
```typescript
|
|
381
|
+
addListener(eventName: 'browserClosed', listenerFunc: () => void) => Promise<PluginListenerHandle>
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
Called when the browser is closed.
|
|
385
|
+
|
|
386
|
+
Only available on Android and iOS.
|
|
387
|
+
|
|
388
|
+
| Param | Type |
|
|
389
|
+
| ------------------ | ---------------------------- |
|
|
390
|
+
| **`eventName`** | <code>'browserClosed'</code> |
|
|
391
|
+
| **`listenerFunc`** | <code>() => void</code> |
|
|
392
|
+
|
|
393
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
394
|
+
|
|
395
|
+
**Since:** 0.1.0
|
|
396
|
+
|
|
397
|
+
--------------------
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
### addListener('browserPageLoaded', ...)
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
addListener(eventName: 'browserPageLoaded', listenerFunc: () => void) => Promise<PluginListenerHandle>
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
Called when the initial page of the browser has finished loading.
|
|
407
|
+
|
|
408
|
+
On Android, this event is only emitted for browsers opened with
|
|
409
|
+
`openInWebView(...)`.
|
|
410
|
+
|
|
411
|
+
Only available on Android and iOS.
|
|
412
|
+
|
|
413
|
+
| Param | Type |
|
|
414
|
+
| ------------------ | -------------------------------- |
|
|
415
|
+
| **`eventName`** | <code>'browserPageLoaded'</code> |
|
|
416
|
+
| **`listenerFunc`** | <code>() => void</code> |
|
|
417
|
+
|
|
418
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
419
|
+
|
|
420
|
+
**Since:** 0.1.0
|
|
421
|
+
|
|
422
|
+
--------------------
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
### addListener('browserPageNavigationCompleted', ...)
|
|
426
|
+
|
|
427
|
+
```typescript
|
|
428
|
+
addListener(eventName: 'browserPageNavigationCompleted', listenerFunc: (event: BrowserPageNavigationCompletedEvent) => void) => Promise<PluginListenerHandle>
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
Called when a page navigation has been completed in the web view.
|
|
432
|
+
|
|
433
|
+
This event is only emitted for browsers opened with `openInWebView(...)`.
|
|
434
|
+
|
|
435
|
+
Only available on Android and iOS.
|
|
436
|
+
|
|
437
|
+
| Param | Type |
|
|
438
|
+
| ------------------ | ----------------------------------------------------------------------------------------------------------------------- |
|
|
439
|
+
| **`eventName`** | <code>'browserPageNavigationCompleted'</code> |
|
|
440
|
+
| **`listenerFunc`** | <code>(event: <a href="#browserpagenavigationcompletedevent">BrowserPageNavigationCompletedEvent</a>) => void</code> |
|
|
441
|
+
|
|
442
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
443
|
+
|
|
444
|
+
**Since:** 0.1.0
|
|
445
|
+
|
|
446
|
+
--------------------
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
### addListener('messageReceived', ...)
|
|
450
|
+
|
|
451
|
+
```typescript
|
|
452
|
+
addListener(eventName: 'messageReceived', listenerFunc: (event: MessageReceivedEvent) => void) => Promise<PluginListenerHandle>
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
Called when the web page posts a message to the app using the injected
|
|
456
|
+
`window.CapacitorInAppBrowser.postMessage(...)` function.
|
|
457
|
+
|
|
458
|
+
This event is only emitted for browsers opened with `openInWebView(...)`.
|
|
459
|
+
|
|
460
|
+
Only available on Android and iOS.
|
|
461
|
+
|
|
462
|
+
| Param | Type |
|
|
463
|
+
| ------------------ | ----------------------------------------------------------------------------------------- |
|
|
464
|
+
| **`eventName`** | <code>'messageReceived'</code> |
|
|
465
|
+
| **`listenerFunc`** | <code>(event: <a href="#messagereceivedevent">MessageReceivedEvent</a>) => void</code> |
|
|
466
|
+
|
|
467
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
468
|
+
|
|
469
|
+
**Since:** 0.1.0
|
|
470
|
+
|
|
471
|
+
--------------------
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
### removeAllListeners()
|
|
475
|
+
|
|
476
|
+
```typescript
|
|
477
|
+
removeAllListeners() => Promise<void>
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
Remove all listeners for this plugin.
|
|
481
|
+
|
|
482
|
+
**Since:** 0.1.0
|
|
483
|
+
|
|
484
|
+
--------------------
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
### Interfaces
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
#### ExecuteScriptResult
|
|
491
|
+
|
|
492
|
+
| Prop | Type | Description | Since |
|
|
493
|
+
| ------------ | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
|
|
494
|
+
| **`result`** | <code>string \| null</code> | The result of the script execution serialized as a JSON string. If the script does not return a JSON-serializable value, `null` is returned. | 0.1.0 |
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
#### ExecuteScriptOptions
|
|
498
|
+
|
|
499
|
+
| Prop | Type | Description | Since |
|
|
500
|
+
| ------------ | ------------------- | ----------------------------------------------- | ----- |
|
|
501
|
+
| **`script`** | <code>string</code> | The JavaScript code to execute in the web view. | 0.1.0 |
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
#### GetCookiesResult
|
|
505
|
+
|
|
506
|
+
| Prop | Type | Description | Since |
|
|
507
|
+
| ------------- | --------------------------------------- | ----------------------------------------------------------- | ----- |
|
|
508
|
+
| **`cookies`** | <code>{ [key: string]: string; }</code> | The cookies for the URL as a map of cookie names to values. | 0.1.0 |
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
#### GetCookiesOptions
|
|
512
|
+
|
|
513
|
+
| Prop | Type | Description | Since |
|
|
514
|
+
| --------- | ------------------- | ------------------------------- | ----- |
|
|
515
|
+
| **`url`** | <code>string</code> | The URL to get the cookies for. | 0.1.0 |
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
#### OpenInExternalBrowserOptions
|
|
519
|
+
|
|
520
|
+
| Prop | Type | Description | Since |
|
|
521
|
+
| --------- | ------------------- | ---------------------------------------- | ----- |
|
|
522
|
+
| **`url`** | <code>string</code> | The URL to open in the external browser. | 0.1.0 |
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
#### OpenInSystemBrowserOptions
|
|
526
|
+
|
|
527
|
+
| Prop | Type | Description | Since |
|
|
528
|
+
| ------------- | ----------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- | ----- |
|
|
529
|
+
| **`android`** | <code><a href="#openinsystembrowserandroidoptions">OpenInSystemBrowserAndroidOptions</a></code> | Options that are only applied on Android. Only available on Android. | 0.1.0 |
|
|
530
|
+
| **`ios`** | <code><a href="#openinsystembrowseriosoptions">OpenInSystemBrowserIosOptions</a></code> | Options that are only applied on iOS. Only available on iOS. | 0.1.0 |
|
|
531
|
+
| **`url`** | <code>string</code> | The URL to open in the system browser. | 0.1.0 |
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
#### OpenInSystemBrowserAndroidOptions
|
|
535
|
+
|
|
536
|
+
| Prop | Type | Description | Default | Since |
|
|
537
|
+
| ------------------------- | -------------------- | ---------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
|
|
538
|
+
| **`hideToolbarOnScroll`** | <code>boolean</code> | Whether or not the toolbar should be hidden when the user scrolls down and shown when the user scrolls up. | <code>false</code> | 0.1.0 |
|
|
539
|
+
| **`showTitle`** | <code>boolean</code> | Whether or not the title of the web page should be shown in the toolbar. | <code>false</code> | 0.1.0 |
|
|
540
|
+
| **`toolbarColor`** | <code>string</code> | The background color of the toolbar as a hex color code. | | 0.1.0 |
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
#### OpenInSystemBrowserIosOptions
|
|
544
|
+
|
|
545
|
+
| Prop | Type | Description | Default | Since |
|
|
546
|
+
| ------------------------ | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------- | ------------------- | ----- |
|
|
547
|
+
| **`barCollapsing`** | <code>boolean</code> | Whether or not the toolbar should collapse when the user scrolls down. | <code>true</code> | 0.1.0 |
|
|
548
|
+
| **`dismissButtonStyle`** | <code><a href="#dismissbuttonstyle">DismissButtonStyle</a></code> | The style of the dismiss button in the toolbar. | <code>'done'</code> | 0.1.0 |
|
|
549
|
+
| **`readerMode`** | <code>boolean</code> | Whether or not the reader mode should be entered if it is available for the web page. | <code>false</code> | 0.1.0 |
|
|
550
|
+
| **`toolbarColor`** | <code>string</code> | The background color of the toolbar as a hex color code. | | 0.1.0 |
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
#### OpenInWebViewOptions
|
|
554
|
+
|
|
555
|
+
| Prop | Type | Description | Default | Since |
|
|
556
|
+
| ------------------------------------- | ----------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- | ----- |
|
|
557
|
+
| **`android`** | <code><a href="#openinwebviewandroidoptions">OpenInWebViewAndroidOptions</a></code> | Options that are only applied on Android. Only available on Android. | | 0.1.0 |
|
|
558
|
+
| **`dataStore`** | <code><a href="#webviewdatastore">WebViewDataStore</a></code> | The data store to use for the web view. On Android, this option is ignored. The web view always uses the app-global (`shared`) data store. Only available on iOS. | <code>'shared'</code> | 0.1.0 |
|
|
559
|
+
| **`headers`** | <code>{ [key: string]: string; }</code> | Additional HTTP headers to send with the initial request. | | 0.1.0 |
|
|
560
|
+
| **`ios`** | <code><a href="#openinwebviewiosoptions">OpenInWebViewIosOptions</a></code> | Options that are only applied on iOS. Only available on iOS. | | 0.1.0 |
|
|
561
|
+
| **`mediaPlaybackRequiresUserAction`** | <code>boolean</code> | Whether or not media playback requires user action. | <code>false</code> | 0.1.0 |
|
|
562
|
+
| **`toolbar`** | <code><a href="#webviewtoolbaroptions">WebViewToolbarOptions</a></code> | Options for the toolbar of the web view. | | 0.1.0 |
|
|
563
|
+
| **`url`** | <code>string</code> | The URL to open in the web view. | | 0.1.0 |
|
|
564
|
+
| **`userAgent`** | <code>string</code> | The custom user agent to use for the web view. | | 0.1.0 |
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
#### OpenInWebViewAndroidOptions
|
|
568
|
+
|
|
569
|
+
| Prop | Type | Description | Default | Since |
|
|
570
|
+
| -------------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
|
|
571
|
+
| **`allowZoom`** | <code>boolean</code> | Whether or not the user can zoom the web page. | <code>false</code> | 0.1.0 |
|
|
572
|
+
| **`hardwareBackButton`** | <code>boolean</code> | Whether or not the hardware back button navigates back in the web view's history before closing the web view. If `false`, the hardware back button closes the web view immediately. | <code>true</code> | 0.1.0 |
|
|
573
|
+
| **`pauseMediaWhenHidden`** | <code>boolean</code> | Whether or not media playback is paused when the app is hidden. | <code>true</code> | 0.1.0 |
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
#### OpenInWebViewIosOptions
|
|
577
|
+
|
|
578
|
+
| Prop | Type | Description | Default | Since |
|
|
579
|
+
| ----------------------------------------- | -------------------- | --------------------------------------------------------------------------------------------- | ------------------ | ----- |
|
|
580
|
+
| **`allowsBackForwardNavigationGestures`** | <code>boolean</code> | Whether or not horizontal swipe gestures navigate back and forward in the web view's history. | <code>false</code> | 0.1.0 |
|
|
581
|
+
| **`overscroll`** | <code>boolean</code> | Whether or not the web view bounces when scrolled past the edge of the content. | <code>true</code> | 0.1.0 |
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
#### WebViewToolbarOptions
|
|
585
|
+
|
|
586
|
+
| Prop | Type | Description | Default | Since |
|
|
587
|
+
| --------------------------- | -------------------- | ------------------------------------------------------------------------------------------------------ | -------------------- | ----- |
|
|
588
|
+
| **`backgroundColor`** | <code>string</code> | The background color of the toolbar as a hex color code. | | 0.1.0 |
|
|
589
|
+
| **`closeButtonText`** | <code>string</code> | The text of the close button in the toolbar. | <code>'Close'</code> | 0.1.0 |
|
|
590
|
+
| **`color`** | <code>string</code> | The text color of the toolbar as a hex color code. | | 0.1.0 |
|
|
591
|
+
| **`showNavigationButtons`** | <code>boolean</code> | Whether or not the back and forward navigation buttons should be shown in the toolbar. | <code>false</code> | 0.1.0 |
|
|
592
|
+
| **`showUrl`** | <code>boolean</code> | Whether or not the current URL should be displayed in the toolbar instead of the title. | <code>false</code> | 0.1.0 |
|
|
593
|
+
| **`title`** | <code>string</code> | The fixed title to display in the toolbar. If not set, the title of the current web page is displayed. | | 0.1.0 |
|
|
594
|
+
| **`visible`** | <code>boolean</code> | Whether or not the toolbar should be visible. | <code>true</code> | 0.1.0 |
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
#### PostMessageOptions
|
|
598
|
+
|
|
599
|
+
| Prop | Type | Description | Since |
|
|
600
|
+
| ---------- | ---------------------------------------- | ----------------------------------------------------------------------------- | ----- |
|
|
601
|
+
| **`data`** | <code>{ [key: string]: unknown; }</code> | The message data to post to the web view. Must be a JSON-serializable object. | 0.1.0 |
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
#### PluginListenerHandle
|
|
605
|
+
|
|
606
|
+
| Prop | Type |
|
|
607
|
+
| ------------ | ----------------------------------------- |
|
|
608
|
+
| **`remove`** | <code>() => Promise<void></code> |
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
#### BrowserPageNavigationCompletedEvent
|
|
612
|
+
|
|
613
|
+
| Prop | Type | Description | Since |
|
|
614
|
+
| --------- | ------------------- | ------------------------------------------ | ----- |
|
|
615
|
+
| **`url`** | <code>string</code> | The URL of the page that was navigated to. | 0.1.0 |
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
#### MessageReceivedEvent
|
|
619
|
+
|
|
620
|
+
| Prop | Type | Description | Since |
|
|
621
|
+
| ---------- | -------------------- | ---------------------------------------- | ----- |
|
|
622
|
+
| **`data`** | <code>unknown</code> | The message data posted by the web page. | 0.1.0 |
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
### Type Aliases
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
#### DismissButtonStyle
|
|
629
|
+
|
|
630
|
+
The style of the dismiss button in the toolbar of the system browser.
|
|
631
|
+
|
|
632
|
+
- `cancel`: A button with the text "Cancel".
|
|
633
|
+
- `close`: A button with the text "Close".
|
|
634
|
+
- `done`: A button with the text "Done".
|
|
635
|
+
|
|
636
|
+
<code>'cancel' | 'close' | 'done'</code>
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
#### WebViewDataStore
|
|
640
|
+
|
|
641
|
+
The data store to use for the web view.
|
|
642
|
+
|
|
643
|
+
- `isolated`: The web view uses a non-persistent data store. Cookies and
|
|
644
|
+
web storage are discarded when the web view is closed.
|
|
645
|
+
- `shared`: The web view uses the app-global data store which is shared
|
|
646
|
+
with other web views.
|
|
647
|
+
|
|
648
|
+
<code>'isolated' | 'shared'</code>
|
|
649
|
+
|
|
650
|
+
</docgen-api>
|
|
651
|
+
|
|
652
|
+
## Messaging
|
|
653
|
+
|
|
654
|
+
The embedded web view injects a small message bridge into every web page. This allows you to exchange messages between your app and the web page in both directions.
|
|
655
|
+
|
|
656
|
+
### From the web page to the app
|
|
657
|
+
|
|
658
|
+
The web page can post a message to the app using the injected `window.CapacitorInAppBrowser.postMessage(...)` function:
|
|
659
|
+
|
|
660
|
+
```javascript
|
|
661
|
+
window.CapacitorInAppBrowser.postMessage({ name: 'Capawesome' });
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
The app receives the message via the `messageReceived` event.
|
|
665
|
+
|
|
666
|
+
### From the app to the web page
|
|
667
|
+
|
|
668
|
+
The app can post a message to the web page using the `postMessage(...)` method. The web page receives the message by listening for the `capacitorInAppBrowserMessage` window event:
|
|
669
|
+
|
|
670
|
+
```javascript
|
|
671
|
+
window.addEventListener('capacitorInAppBrowserMessage', event => {
|
|
672
|
+
console.log('Message received', event.detail);
|
|
673
|
+
});
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
## Platform Behavior
|
|
677
|
+
|
|
678
|
+
The three browser modes behave differently on each platform. Keep the following differences in mind:
|
|
679
|
+
|
|
680
|
+
- **System browser**: Tracking the visited URLs is not possible by design. If you need the `browserPageNavigationCompleted` event, use the `openInWebView(...)` method instead. On Android, the `browserPageLoaded` event is not emitted for the system browser and the `browserClosed` event is emitted when the user returns to the app.
|
|
681
|
+
- **Embedded web view**: The web view always uses the app-global (`shared`) data store on Android. The `dataStore` option is only supported on iOS. On iOS, hiding the toolbar removes the close button, so the browser can then only be closed using the `close(...)` method.
|
|
682
|
+
- **External browser**: The browser is opened in a separate app. For this reason, no events are emitted and the `close(...)` method has no effect.
|
|
683
|
+
|
|
684
|
+
## Changelog
|
|
685
|
+
|
|
686
|
+
See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/in-app-browser/CHANGELOG.md).
|
|
687
|
+
|
|
688
|
+
## License
|
|
689
|
+
|
|
690
|
+
See [LICENSE](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/in-app-browser/LICENSE).
|