@capawesome/capacitor-in-app-browser 0.0.2 → 0.1.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/README.md CHANGED
@@ -10,7 +10,7 @@ Capacitor plugin to open URLs in the external browser, the system browser or an
10
10
 
11
11
  ## Features
12
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:
13
+ The Capacitor In-App Browser plugin is one of the most complete in-app browsing solutions for Capacitor apps. Here are some of the key features:
14
14
 
15
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
16
  - 🧭 **Navigation events**: Get notified when the browser is closed, a page has been loaded or a navigation has been completed.
@@ -24,9 +24,15 @@ We are proud to offer one of the most complete and feature-rich Capacitor plugin
24
24
 
25
25
  Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
26
26
 
27
- ## Newsletter
27
+ ## Use Cases
28
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/).
29
+ The In-App Browser plugin is typically used whenever an app needs to display web content without losing the user, for example:
30
+
31
+ - **External links**: Open links, terms of service, or documentation in the system browser without leaving the app context.
32
+ - **Login and checkout flows**: Open a web-based flow in the embedded web view and watch for a redirect using the `browserUrlChanged` event.
33
+ - **Hybrid web content**: Embed a web page with a themed native toolbar and exchange messages between the app and the page.
34
+ - **Background loading**: Load a URL in a hidden web view with the `visible` option and present it once the page has loaded.
35
+ - **Session control**: Clear the cache and session data of the web view, or use an isolated data store on iOS.
30
36
 
31
37
  ## Compatibility
32
38
 
@@ -96,6 +102,12 @@ No configuration required for this plugin.
96
102
 
97
103
  ## Usage
98
104
 
105
+ The following examples show how to open URLs in the external, system, and in-app browsers, control the embedded web view, exchange messages with the loaded page, clear browsing data, and listen for browser events.
106
+
107
+ ### Open a URL in the external browser
108
+
109
+ Open a URL in the default browser app of the device. Since the browser is opened in a separate app, no events are emitted in this mode:
110
+
99
111
  ```typescript
100
112
  import { InAppBrowser } from '@capawesome/capacitor-in-app-browser';
101
113
 
@@ -104,6 +116,14 @@ const openInExternalBrowser = async () => {
104
116
  url: 'https://capawesome.io',
105
117
  });
106
118
  };
119
+ ```
120
+
121
+ ### Open a URL in the system browser
122
+
123
+ Open a URL in the system browser (Custom Tabs on Android, `SFSafariViewController` on iOS) and customize the toolbar with platform-specific options. Only available on Android and iOS:
124
+
125
+ ```typescript
126
+ import { InAppBrowser } from '@capawesome/capacitor-in-app-browser';
107
127
 
108
128
  const openInSystemBrowser = async () => {
109
129
  await InAppBrowser.openInSystemBrowser({
@@ -118,6 +138,14 @@ const openInSystemBrowser = async () => {
118
138
  },
119
139
  });
120
140
  };
141
+ ```
142
+
143
+ ### Open a URL in an embedded web view
144
+
145
+ Open a URL in an embedded web view with a native toolbar whose color, title, and buttons can be customized. Only available on Android and iOS:
146
+
147
+ ```typescript
148
+ import { InAppBrowser } from '@capawesome/capacitor-in-app-browser';
121
149
 
122
150
  const openInWebView = async () => {
123
151
  await InAppBrowser.openInWebView({
@@ -129,10 +157,26 @@ const openInWebView = async () => {
129
157
  },
130
158
  });
131
159
  };
160
+ ```
161
+
162
+ ### Close the browser
163
+
164
+ Close the currently open browser. This closes browsers opened with `openInWebView(...)` or `openInSystemBrowser(...)`. Only available on Android and iOS:
165
+
166
+ ```typescript
167
+ import { InAppBrowser } from '@capawesome/capacitor-in-app-browser';
132
168
 
133
169
  const close = async () => {
134
170
  await InAppBrowser.close();
135
171
  };
172
+ ```
173
+
174
+ ### Execute JavaScript in the web view
175
+
176
+ Execute any JavaScript code in the currently open web view. This method is only available for browsers opened with `openInWebView(...)` on Android and iOS:
177
+
178
+ ```typescript
179
+ import { InAppBrowser } from '@capawesome/capacitor-in-app-browser';
136
180
 
137
181
  const executeScript = async () => {
138
182
  const { result } = await InAppBrowser.executeScript({
@@ -140,12 +184,28 @@ const executeScript = async () => {
140
184
  });
141
185
  return result;
142
186
  };
187
+ ```
188
+
189
+ ### Post a message to the web page
190
+
191
+ Post a message to the currently open web view. The web page receives the message by listening for the `capacitorInAppBrowserMessage` window event, see [Messaging](#messaging). This method is only available for browsers opened with `openInWebView(...)` on Android and iOS:
192
+
193
+ ```typescript
194
+ import { InAppBrowser } from '@capawesome/capacitor-in-app-browser';
143
195
 
144
196
  const postMessage = async () => {
145
197
  await InAppBrowser.postMessage({
146
198
  data: { name: 'Capawesome' },
147
199
  });
148
200
  };
201
+ ```
202
+
203
+ ### Clear the cache and session data
204
+
205
+ Clear the cache or the session data (cookies and web storage) of the web view. Only available on Android and iOS:
206
+
207
+ ```typescript
208
+ import { InAppBrowser } from '@capawesome/capacitor-in-app-browser';
149
209
 
150
210
  const clearCache = async () => {
151
211
  await InAppBrowser.clearCache();
@@ -154,6 +214,14 @@ const clearCache = async () => {
154
214
  const clearSessionData = async () => {
155
215
  await InAppBrowser.clearSessionData();
156
216
  };
217
+ ```
218
+
219
+ ### Listen for browser events
220
+
221
+ Get notified when the browser is closed, a message is received, a navigation has been completed, a page has been loaded, or the URL has changed:
222
+
223
+ ```typescript
224
+ import { InAppBrowser } from '@capawesome/capacitor-in-app-browser';
157
225
 
158
226
  const addListeners = async () => {
159
227
  await InAppBrowser.addListener('browserClosed', () => {
@@ -741,6 +809,46 @@ The three browser modes behave differently on each platform. Keep the following
741
809
  - **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.
742
810
  - **External browser**: The browser is opened in a separate app. For this reason, no events are emitted and the `close(...)` method has no effect.
743
811
 
812
+ ## FAQ
813
+
814
+ ### How is this plugin different from other similar plugins?
815
+
816
+ It covers three browsing modes in one fully typed API — the external browser, the system browser (Custom Tabs on Android, `SFSafariViewController` on iOS), and an embedded web view with a themed native toolbar, JavaScript execution, two-way messaging, navigation events, and session control. Camera and microphone requests from web pages are forwarded to the app, and you can even load a URL hidden in the background and present it once it's ready. If you only need to open a link, the external mode is a simple one-liner; if you need to embed, theme, and communicate with web content, this plugin is designed for exactly that.
817
+
818
+ ### What is the difference between the external browser, the system browser and the embedded web view?
819
+
820
+ The `openInExternalBrowser(...)` method opens the URL in the default browser app of the device, so no events are emitted and the `close()` method has no effect. The `openInSystemBrowser(...)` method presents the system browser (Custom Tabs on Android, `SFSafariViewController` on iOS) inside your app with a customizable toolbar. The `openInWebView(...)` method opens an embedded web view with a native toolbar and offers the most control, including JavaScript execution, messaging, and navigation events. See [Platform Behavior](#platform-behavior) for the differences between the modes.
821
+
822
+ ### How can I track which URLs the user visits?
823
+
824
+ Tracking the visited URLs is only possible in the embedded web view. Open the URL with `openInWebView(...)` and listen for the `browserUrlChanged` or `browserNavigationCompleted` event. In the system browser, tracking the visited URLs is not possible by design, and in the external browser no events are emitted at all.
825
+
826
+ ### How can I exchange data between my app and the opened web page?
827
+
828
+ The embedded web view injects a small message bridge into every web page. The web page can post messages to the app using the injected `window.CapacitorInAppBrowser.postMessage(...)` function, which the app receives via the `browserMessageReceived` event. The app can post messages to the web page using the `postMessage(...)` method, which the web page receives via the `capacitorInAppBrowserMessage` window event. See [Messaging](#messaging) for more details.
829
+
830
+ ### Can web pages access the camera or microphone?
831
+
832
+ Yes, camera and microphone permission requests from web pages opened in the embedded web view are forwarded to the app. On Android, the corresponding permissions must be declared in your `AndroidManifest.xml` and granted before a web page requests access. On iOS, the `NSCameraUsageDescription` and `NSMicrophoneUsageDescription` keys must be added to your `Info.plist` file. See [Installation](#installation) for details.
833
+
834
+ ### Can I load a URL in the background before showing it?
835
+
836
+ Yes, open the URL with `openInWebView(...)` and set the `visible` option to `false`. The web view then loads the URL in the background and stays hidden until you call the `show()` method. The `browserPageLoaded` event is still emitted and `close()` can be called while the web view is hidden.
837
+
838
+ ### Can I use this plugin with Ionic, React, Vue or Angular?
839
+
840
+ Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.
841
+
842
+ ## Related Plugins
843
+
844
+ - [App Launcher](https://capawesome.io/docs/sdks/capacitor/app-launcher/): Check if an app can be opened and open it.
845
+ - [OAuth](https://capawesome.io/docs/sdks/capacitor/oauth/): Communicate with OAuth 2.0 and OpenID Connect providers.
846
+ - [System WebView](https://capawesome.io/docs/sdks/capacitor/system-webview/): Detect an outdated Android System WebView and guide users to update it.
847
+
848
+ ## Newsletter
849
+
850
+ 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/).
851
+
744
852
  ## Changelog
745
853
 
746
854
  See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/in-app-browser/CHANGELOG.md).
@@ -31,7 +31,7 @@ android {
31
31
  buildTypes {
32
32
  release {
33
33
  minifyEnabled false
34
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
35
35
  }
36
36
  }
37
37
  lintOptions {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capawesome/capacitor-in-app-browser",
3
- "version": "0.0.2",
4
- "description": "Capacitor plugin to open URLs in the external browser, the system browser or an embedded web view.",
3
+ "version": "0.1.1",
4
+ "description": "Capacitor plugin to open URLs in the external browser, the system browser or an embedded web view on Android, iOS, and Web.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/esm/index.d.ts",
@@ -37,7 +37,15 @@
37
37
  "keywords": [
38
38
  "capacitor",
39
39
  "plugin",
40
- "native"
40
+ "native",
41
+ "capacitor-plugin",
42
+ "in-app browser",
43
+ "inappbrowser",
44
+ "browser",
45
+ "webview",
46
+ "custom tabs",
47
+ "safari view controller",
48
+ "open url"
41
49
  ],
42
50
  "scripts": {
43
51
  "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",