@capawesome/capacitor-in-app-browser 0.1.1 → 0.2.0
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 +34 -11
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/InAppBrowser.java +152 -141
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/InAppBrowserPlugin.java +4 -2
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/classes/options/ClearCookiesOptions.java +21 -0
- package/dist/docs.json +45 -7
- package/dist/esm/definitions.d.ts +20 -3
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +1 -1
- package/dist/esm/web.js +1 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +1 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1 -1
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/Classes/Options/ClearCookiesOptions.swift +20 -0
- package/ios/Plugin/InAppBrowser.swift +23 -4
- package/ios/Plugin/InAppBrowserPlugin.swift +15 -9
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -17,8 +17,9 @@ The Capacitor In-App Browser plugin is one of the most complete in-app browsing
|
|
|
17
17
|
- 💉 **JavaScript execution**: Execute any JavaScript code in the embedded web view.
|
|
18
18
|
- 💬 **Messaging**: Exchange messages between your app and the web page in both directions.
|
|
19
19
|
- 🎨 **Toolbar theming**: Customize the toolbar color, title, close button and navigation buttons.
|
|
20
|
-
- 🍪 **Session control**: Clear the cache and
|
|
20
|
+
- 🍪 **Session control**: Clear the cache and cookies, or use an isolated data store on iOS.
|
|
21
21
|
- 🎥 **Media permissions**: Camera and microphone permission requests from web pages are forwarded to the app.
|
|
22
|
+
- 🤝 **Compatibility**: Works alongside the [App Launcher](https://capawesome.io/docs/sdks/capacitor/app-launcher/), [OAuth](https://capawesome.io/docs/sdks/capacitor/oauth/) and [System WebView](https://capawesome.io/docs/sdks/capacitor/system-webview/) plugins.
|
|
22
23
|
- 📦 **CocoaPods & SPM**: Supports CocoaPods and Swift Package Manager for iOS.
|
|
23
24
|
- 🔁 **Up-to-date**: Always supports the latest Capacitor version.
|
|
24
25
|
|
|
@@ -32,7 +33,7 @@ The In-App Browser plugin is typically used whenever an app needs to display web
|
|
|
32
33
|
- **Login and checkout flows**: Open a web-based flow in the embedded web view and watch for a redirect using the `browserUrlChanged` event.
|
|
33
34
|
- **Hybrid web content**: Embed a web page with a themed native toolbar and exchange messages between the app and the page.
|
|
34
35
|
- **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
|
|
36
|
+
- **Session control**: Clear the cache and cookies of the web view, or use an isolated data store on iOS.
|
|
36
37
|
|
|
37
38
|
## Compatibility
|
|
38
39
|
|
|
@@ -200,9 +201,9 @@ const postMessage = async () => {
|
|
|
200
201
|
};
|
|
201
202
|
```
|
|
202
203
|
|
|
203
|
-
### Clear the cache and
|
|
204
|
+
### Clear the cache and cookies
|
|
204
205
|
|
|
205
|
-
Clear the cache or the
|
|
206
|
+
Clear the cache or the cookies of the web view, either for all URLs or only for a specific URL. Only available on Android and iOS:
|
|
206
207
|
|
|
207
208
|
```typescript
|
|
208
209
|
import { InAppBrowser } from '@capawesome/capacitor-in-app-browser';
|
|
@@ -211,8 +212,12 @@ const clearCache = async () => {
|
|
|
211
212
|
await InAppBrowser.clearCache();
|
|
212
213
|
};
|
|
213
214
|
|
|
214
|
-
const
|
|
215
|
-
await InAppBrowser.
|
|
215
|
+
const clearAllCookies = async () => {
|
|
216
|
+
await InAppBrowser.clearCookies();
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const clearCookiesForUrl = async () => {
|
|
220
|
+
await InAppBrowser.clearCookies({ url: 'https://capawesome.io' });
|
|
216
221
|
};
|
|
217
222
|
```
|
|
218
223
|
|
|
@@ -247,7 +252,7 @@ const addListeners = async () => {
|
|
|
247
252
|
<docgen-index>
|
|
248
253
|
|
|
249
254
|
* [`clearCache()`](#clearcache)
|
|
250
|
-
* [`
|
|
255
|
+
* [`clearCookies(...)`](#clearcookies)
|
|
251
256
|
* [`close()`](#close)
|
|
252
257
|
* [`executeScript(...)`](#executescript)
|
|
253
258
|
* [`getCookies(...)`](#getcookies)
|
|
@@ -285,17 +290,24 @@ Only available on Android and iOS.
|
|
|
285
290
|
--------------------
|
|
286
291
|
|
|
287
292
|
|
|
288
|
-
###
|
|
293
|
+
### clearCookies(...)
|
|
289
294
|
|
|
290
295
|
```typescript
|
|
291
|
-
|
|
296
|
+
clearCookies(options?: ClearCookiesOptions | undefined) => Promise<void>
|
|
292
297
|
```
|
|
293
298
|
|
|
294
|
-
Clear the
|
|
299
|
+
Clear the cookies of the web view.
|
|
300
|
+
|
|
301
|
+
Provide the `url` option to clear only the cookies of a specific URL.
|
|
302
|
+
Otherwise, all cookies are cleared.
|
|
295
303
|
|
|
296
304
|
Only available on Android and iOS.
|
|
297
305
|
|
|
298
|
-
|
|
306
|
+
| Param | Type |
|
|
307
|
+
| ------------- | ------------------------------------------------------------------- |
|
|
308
|
+
| **`options`** | <code><a href="#clearcookiesoptions">ClearCookiesOptions</a></code> |
|
|
309
|
+
|
|
310
|
+
**Since:** 0.2.0
|
|
299
311
|
|
|
300
312
|
--------------------
|
|
301
313
|
|
|
@@ -607,6 +619,13 @@ Remove all listeners for this plugin.
|
|
|
607
619
|
### Interfaces
|
|
608
620
|
|
|
609
621
|
|
|
622
|
+
#### ClearCookiesOptions
|
|
623
|
+
|
|
624
|
+
| Prop | Type | Description | Since |
|
|
625
|
+
| --------- | ------------------- | --------------------------------------------------------------------------- | ----- |
|
|
626
|
+
| **`url`** | <code>string</code> | The URL to clear the cookies for. If not provided, all cookies are cleared. | 0.2.0 |
|
|
627
|
+
|
|
628
|
+
|
|
610
629
|
#### ExecuteScriptResult
|
|
611
630
|
|
|
612
631
|
| Prop | Type | Description | Since |
|
|
@@ -853,6 +872,10 @@ Stay up to date with the latest news and updates about the Capawesome, Capacitor
|
|
|
853
872
|
|
|
854
873
|
See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/in-app-browser/CHANGELOG.md).
|
|
855
874
|
|
|
875
|
+
## Breaking Changes
|
|
876
|
+
|
|
877
|
+
See [BREAKING.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/in-app-browser/BREAKING.md).
|
|
878
|
+
|
|
856
879
|
## License
|
|
857
880
|
|
|
858
881
|
See [LICENSE](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/in-app-browser/LICENSE).
|
package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/InAppBrowser.java
CHANGED
|
@@ -2,8 +2,8 @@ package io.capawesome.capacitorjs.plugins.inappbrowser;
|
|
|
2
2
|
|
|
3
3
|
import android.content.ActivityNotFoundException;
|
|
4
4
|
import android.content.Intent;
|
|
5
|
+
import android.net.Uri;
|
|
5
6
|
import android.webkit.CookieManager;
|
|
6
|
-
import android.webkit.WebStorage;
|
|
7
7
|
import android.webkit.WebView;
|
|
8
8
|
import androidx.annotation.NonNull;
|
|
9
9
|
import androidx.annotation.Nullable;
|
|
@@ -14,6 +14,7 @@ import io.capawesome.capacitorjs.plugins.inappbrowser.classes.WebViewDialog;
|
|
|
14
14
|
import io.capawesome.capacitorjs.plugins.inappbrowser.classes.events.BrowserMessageReceivedEvent;
|
|
15
15
|
import io.capawesome.capacitorjs.plugins.inappbrowser.classes.events.BrowserNavigationCompletedEvent;
|
|
16
16
|
import io.capawesome.capacitorjs.plugins.inappbrowser.classes.events.BrowserUrlChangedEvent;
|
|
17
|
+
import io.capawesome.capacitorjs.plugins.inappbrowser.classes.options.ClearCookiesOptions;
|
|
17
18
|
import io.capawesome.capacitorjs.plugins.inappbrowser.classes.options.ExecuteScriptOptions;
|
|
18
19
|
import io.capawesome.capacitorjs.plugins.inappbrowser.classes.options.GetCookiesOptions;
|
|
19
20
|
import io.capawesome.capacitorjs.plugins.inappbrowser.classes.options.OpenInExternalBrowserOptions;
|
|
@@ -44,85 +45,91 @@ public class InAppBrowser {
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
public void clearCache(@NonNull EmptyCallback callback) {
|
|
47
|
-
plugin
|
|
48
|
-
.
|
|
49
|
-
.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
callback.success();
|
|
54
|
-
});
|
|
48
|
+
plugin.getActivity().runOnUiThread(() -> {
|
|
49
|
+
WebView webView = new WebView(plugin.getContext());
|
|
50
|
+
webView.clearCache(true);
|
|
51
|
+
webView.destroy();
|
|
52
|
+
callback.success();
|
|
53
|
+
});
|
|
55
54
|
}
|
|
56
55
|
|
|
57
|
-
public void
|
|
58
|
-
plugin
|
|
59
|
-
.
|
|
60
|
-
.
|
|
61
|
-
|
|
56
|
+
public void clearCookies(@NonNull ClearCookiesOptions options, @NonNull EmptyCallback callback) {
|
|
57
|
+
plugin.getActivity().runOnUiThread(() -> {
|
|
58
|
+
CookieManager cookieManager = CookieManager.getInstance();
|
|
59
|
+
String url = options.getUrl();
|
|
60
|
+
if (url == null) {
|
|
62
61
|
cookieManager.removeAllCookies(value -> {
|
|
63
62
|
cookieManager.flush();
|
|
64
|
-
WebStorage.getInstance().deleteAllData();
|
|
65
63
|
callback.success();
|
|
66
64
|
});
|
|
67
|
-
}
|
|
65
|
+
} else {
|
|
66
|
+
String cookieString = cookieManager.getCookie(url);
|
|
67
|
+
if (cookieString != null) {
|
|
68
|
+
String host = Uri.parse(url).getHost();
|
|
69
|
+
for (String cookie : cookieString.split("; ")) {
|
|
70
|
+
int separatorIndex = cookie.indexOf('=');
|
|
71
|
+
if (separatorIndex < 0) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
expireCookie(cookieManager, url, host, cookie.substring(0, separatorIndex));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
cookieManager.flush();
|
|
78
|
+
callback.success();
|
|
79
|
+
}
|
|
80
|
+
});
|
|
68
81
|
}
|
|
69
82
|
|
|
70
83
|
public void close(@NonNull EmptyCallback callback) {
|
|
71
|
-
plugin
|
|
72
|
-
.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
callback.error(CustomExceptions.NO_BROWSER_OPEN);
|
|
88
|
-
});
|
|
84
|
+
plugin.getActivity().runOnUiThread(() -> {
|
|
85
|
+
WebViewDialog webViewDialog = this.webViewDialog;
|
|
86
|
+
if (webViewDialog != null) {
|
|
87
|
+
webViewDialog.dismiss();
|
|
88
|
+
callback.success();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (customTabOpened) {
|
|
92
|
+
Intent intent = new Intent(plugin.getContext(), plugin.getActivity().getClass());
|
|
93
|
+
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
|
94
|
+
plugin.getActivity().startActivity(intent);
|
|
95
|
+
callback.success();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
callback.error(CustomExceptions.NO_BROWSER_OPEN);
|
|
99
|
+
});
|
|
89
100
|
}
|
|
90
101
|
|
|
91
102
|
public void executeScript(@NonNull ExecuteScriptOptions options, @NonNull NonEmptyResultCallback<ExecuteScriptResult> callback) {
|
|
92
|
-
plugin
|
|
93
|
-
.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
String result = value == null || value.equals("null") ? null : value;
|
|
102
|
-
callback.success(new ExecuteScriptResult(result));
|
|
103
|
-
});
|
|
103
|
+
plugin.getActivity().runOnUiThread(() -> {
|
|
104
|
+
WebViewDialog webViewDialog = this.webViewDialog;
|
|
105
|
+
if (webViewDialog == null) {
|
|
106
|
+
callback.error(CustomExceptions.NO_BROWSER_OPEN);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
webViewDialog.executeScript(options.getScript(), value -> {
|
|
110
|
+
String result = value == null || value.equals("null") ? null : value;
|
|
111
|
+
callback.success(new ExecuteScriptResult(result));
|
|
104
112
|
});
|
|
113
|
+
});
|
|
105
114
|
}
|
|
106
115
|
|
|
107
116
|
public void getCookies(@NonNull GetCookiesOptions options, @NonNull NonEmptyResultCallback<GetCookiesResult> callback) {
|
|
108
|
-
plugin
|
|
109
|
-
|
|
110
|
-
.
|
|
111
|
-
|
|
112
|
-
String
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (separatorIndex < 0) {
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
String name = cookie.substring(0, separatorIndex);
|
|
120
|
-
String value = cookie.substring(separatorIndex + 1);
|
|
121
|
-
cookies.put(name, value);
|
|
117
|
+
plugin.getActivity().runOnUiThread(() -> {
|
|
118
|
+
Map<String, String> cookies = new HashMap<>();
|
|
119
|
+
String cookieString = CookieManager.getInstance().getCookie(options.getUrl());
|
|
120
|
+
if (cookieString != null) {
|
|
121
|
+
for (String cookie : cookieString.split("; ")) {
|
|
122
|
+
int separatorIndex = cookie.indexOf('=');
|
|
123
|
+
if (separatorIndex < 0) {
|
|
124
|
+
continue;
|
|
122
125
|
}
|
|
126
|
+
String name = cookie.substring(0, separatorIndex);
|
|
127
|
+
String value = cookie.substring(separatorIndex + 1);
|
|
128
|
+
cookies.put(name, value);
|
|
123
129
|
}
|
|
124
|
-
|
|
125
|
-
|
|
130
|
+
}
|
|
131
|
+
callback.success(new GetCookiesResult(cookies));
|
|
132
|
+
});
|
|
126
133
|
}
|
|
127
134
|
|
|
128
135
|
public void handleOnPause() {
|
|
@@ -154,100 +161,92 @@ public class InAppBrowser {
|
|
|
154
161
|
}
|
|
155
162
|
|
|
156
163
|
public void openInSystemBrowser(@NonNull OpenInSystemBrowserOptions options, @NonNull EmptyCallback callback) {
|
|
157
|
-
plugin
|
|
158
|
-
.
|
|
159
|
-
.
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
});
|
|
164
|
+
plugin.getActivity().runOnUiThread(() -> {
|
|
165
|
+
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
|
|
166
|
+
Integer toolbarColor = options.getToolbarColor();
|
|
167
|
+
if (toolbarColor != null) {
|
|
168
|
+
builder.setDefaultColorSchemeParams(new CustomTabColorSchemeParams.Builder().setToolbarColor(toolbarColor).build());
|
|
169
|
+
}
|
|
170
|
+
builder.setShowTitle(options.getShowTitle());
|
|
171
|
+
builder.setUrlBarHidingEnabled(options.getHideToolbarOnScroll());
|
|
172
|
+
CustomTabsIntent customTabsIntent = builder.build();
|
|
173
|
+
try {
|
|
174
|
+
customTabsIntent.launchUrl(plugin.getActivity(), options.getUri());
|
|
175
|
+
customTabOpened = true;
|
|
176
|
+
callback.success();
|
|
177
|
+
} catch (ActivityNotFoundException exception) {
|
|
178
|
+
callback.error(CustomExceptions.BROWSER_NOT_FOUND);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
176
181
|
}
|
|
177
182
|
|
|
178
183
|
public void openInWebView(@NonNull OpenInWebViewOptions options, @NonNull EmptyCallback callback) {
|
|
179
|
-
plugin
|
|
180
|
-
.
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (InAppBrowser.this.webViewDialog == dialog) {
|
|
193
|
-
InAppBrowser.this.webViewDialog = null;
|
|
194
|
-
}
|
|
195
|
-
plugin.notifyBrowserClosedListeners();
|
|
184
|
+
plugin.getActivity().runOnUiThread(() -> {
|
|
185
|
+
WebViewDialog existingWebViewDialog = this.webViewDialog;
|
|
186
|
+
if (existingWebViewDialog != null) {
|
|
187
|
+
existingWebViewDialog.dismiss();
|
|
188
|
+
}
|
|
189
|
+
WebViewDialog webViewDialog = new WebViewDialog(
|
|
190
|
+
plugin.getActivity(),
|
|
191
|
+
options,
|
|
192
|
+
new WebViewDialog.Listener() {
|
|
193
|
+
@Override
|
|
194
|
+
public void onClosed(@NonNull WebViewDialog dialog) {
|
|
195
|
+
if (InAppBrowser.this.webViewDialog == dialog) {
|
|
196
|
+
InAppBrowser.this.webViewDialog = null;
|
|
196
197
|
}
|
|
198
|
+
plugin.notifyBrowserClosedListeners();
|
|
199
|
+
}
|
|
197
200
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
201
|
+
@Override
|
|
202
|
+
public void onMessageReceived(@NonNull String data) {
|
|
203
|
+
handleMessageReceived(data);
|
|
204
|
+
}
|
|
202
205
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
206
|
+
@Override
|
|
207
|
+
public void onNavigationCompleted(@NonNull String url) {
|
|
208
|
+
plugin.notifyBrowserNavigationCompletedListeners(new BrowserNavigationCompletedEvent(url));
|
|
209
|
+
}
|
|
207
210
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
211
|
+
@Override
|
|
212
|
+
public void onPageLoaded() {
|
|
213
|
+
plugin.notifyBrowserPageLoadedListeners();
|
|
214
|
+
}
|
|
212
215
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
216
|
+
@Override
|
|
217
|
+
public void onUrlChanged(@NonNull String url) {
|
|
218
|
+
plugin.notifyBrowserUrlChangedListeners(new BrowserUrlChangedEvent(url));
|
|
217
219
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
220
|
+
}
|
|
221
|
+
);
|
|
222
|
+
this.webViewDialog = webViewDialog;
|
|
223
|
+
webViewDialog.show();
|
|
224
|
+
callback.success();
|
|
225
|
+
});
|
|
223
226
|
}
|
|
224
227
|
|
|
225
228
|
public void postMessage(@NonNull PostMessageOptions options, @NonNull EmptyCallback callback) {
|
|
226
|
-
plugin
|
|
227
|
-
.
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
callback.success();
|
|
236
|
-
});
|
|
229
|
+
plugin.getActivity().runOnUiThread(() -> {
|
|
230
|
+
WebViewDialog webViewDialog = this.webViewDialog;
|
|
231
|
+
if (webViewDialog == null) {
|
|
232
|
+
callback.error(CustomExceptions.NO_BROWSER_OPEN);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
webViewDialog.postMessage(options.getData().toString());
|
|
236
|
+
callback.success();
|
|
237
|
+
});
|
|
237
238
|
}
|
|
238
239
|
|
|
239
240
|
public void show(@NonNull EmptyCallback callback) {
|
|
240
|
-
plugin
|
|
241
|
-
.
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
callback.success();
|
|
250
|
-
});
|
|
241
|
+
plugin.getActivity().runOnUiThread(() -> {
|
|
242
|
+
WebViewDialog webViewDialog = this.webViewDialog;
|
|
243
|
+
if (webViewDialog == null) {
|
|
244
|
+
callback.error(CustomExceptions.NO_BROWSER_OPEN);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
webViewDialog.showWebView();
|
|
248
|
+
callback.success();
|
|
249
|
+
});
|
|
251
250
|
}
|
|
252
251
|
|
|
253
252
|
private void handleMessageReceived(@NonNull String data) {
|
|
@@ -259,4 +258,16 @@ public class InAppBrowser {
|
|
|
259
258
|
}
|
|
260
259
|
plugin.notifyBrowserMessageReceivedListeners(new BrowserMessageReceivedEvent(value));
|
|
261
260
|
}
|
|
261
|
+
|
|
262
|
+
private void expireCookie(@NonNull CookieManager cookieManager, @NonNull String url, @Nullable String host, @NonNull String name) {
|
|
263
|
+
String expiredCookie = name + "=; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=0; Path=/";
|
|
264
|
+
cookieManager.setCookie(url, expiredCookie);
|
|
265
|
+
// Also expire the domain cookie variants of all parent domains
|
|
266
|
+
// because the cookie string does not reveal the cookie domain.
|
|
267
|
+
String domain = host;
|
|
268
|
+
while (domain != null && domain.indexOf('.') != -1) {
|
|
269
|
+
cookieManager.setCookie(url, expiredCookie + "; Domain=" + domain);
|
|
270
|
+
domain = domain.substring(domain.indexOf('.') + 1);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
262
273
|
}
|
package/android/src/main/java/io/capawesome/capacitorjs/plugins/inappbrowser/InAppBrowserPlugin.java
CHANGED
|
@@ -12,6 +12,7 @@ import io.capawesome.capacitorjs.plugins.inappbrowser.classes.CustomException;
|
|
|
12
12
|
import io.capawesome.capacitorjs.plugins.inappbrowser.classes.events.BrowserMessageReceivedEvent;
|
|
13
13
|
import io.capawesome.capacitorjs.plugins.inappbrowser.classes.events.BrowserNavigationCompletedEvent;
|
|
14
14
|
import io.capawesome.capacitorjs.plugins.inappbrowser.classes.events.BrowserUrlChangedEvent;
|
|
15
|
+
import io.capawesome.capacitorjs.plugins.inappbrowser.classes.options.ClearCookiesOptions;
|
|
15
16
|
import io.capawesome.capacitorjs.plugins.inappbrowser.classes.options.ExecuteScriptOptions;
|
|
16
17
|
import io.capawesome.capacitorjs.plugins.inappbrowser.classes.options.GetCookiesOptions;
|
|
17
18
|
import io.capawesome.capacitorjs.plugins.inappbrowser.classes.options.OpenInExternalBrowserOptions;
|
|
@@ -60,8 +61,9 @@ public class InAppBrowserPlugin extends Plugin {
|
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
@PluginMethod
|
|
63
|
-
public void
|
|
64
|
+
public void clearCookies(PluginCall call) {
|
|
64
65
|
try {
|
|
66
|
+
ClearCookiesOptions options = new ClearCookiesOptions(call);
|
|
65
67
|
EmptyCallback callback = new EmptyCallback() {
|
|
66
68
|
@Override
|
|
67
69
|
public void success() {
|
|
@@ -74,7 +76,7 @@ public class InAppBrowserPlugin extends Plugin {
|
|
|
74
76
|
}
|
|
75
77
|
};
|
|
76
78
|
|
|
77
|
-
implementation.
|
|
79
|
+
implementation.clearCookies(options, callback);
|
|
78
80
|
} catch (Exception exception) {
|
|
79
81
|
rejectCall(call, exception);
|
|
80
82
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.inappbrowser.classes.options;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
import com.getcapacitor.PluginCall;
|
|
6
|
+
|
|
7
|
+
public class ClearCookiesOptions {
|
|
8
|
+
|
|
9
|
+
@Nullable
|
|
10
|
+
private final String url;
|
|
11
|
+
|
|
12
|
+
public ClearCookiesOptions(@NonNull PluginCall call) {
|
|
13
|
+
String url = call.getString("url");
|
|
14
|
+
this.url = url == null || url.isEmpty() ? null : url;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@Nullable
|
|
18
|
+
public String getUrl() {
|
|
19
|
+
return url;
|
|
20
|
+
}
|
|
21
|
+
}
|
package/dist/docs.json
CHANGED
|
@@ -21,19 +21,27 @@
|
|
|
21
21
|
"slug": "clearcache"
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
|
-
"name": "
|
|
25
|
-
"signature": "() => Promise<void>",
|
|
26
|
-
"parameters": [
|
|
24
|
+
"name": "clearCookies",
|
|
25
|
+
"signature": "(options?: ClearCookiesOptions | undefined) => Promise<void>",
|
|
26
|
+
"parameters": [
|
|
27
|
+
{
|
|
28
|
+
"name": "options",
|
|
29
|
+
"docs": "",
|
|
30
|
+
"type": "ClearCookiesOptions | undefined"
|
|
31
|
+
}
|
|
32
|
+
],
|
|
27
33
|
"returns": "Promise<void>",
|
|
28
34
|
"tags": [
|
|
29
35
|
{
|
|
30
36
|
"name": "since",
|
|
31
|
-
"text": "0.
|
|
37
|
+
"text": "0.2.0"
|
|
32
38
|
}
|
|
33
39
|
],
|
|
34
|
-
"docs": "Clear the
|
|
35
|
-
"complexTypes": [
|
|
36
|
-
|
|
40
|
+
"docs": "Clear the cookies of the web view.\n\nProvide the `url` option to clear only the cookies of a specific URL.\nOtherwise, all cookies are cleared.\n\nOnly available on Android and iOS.",
|
|
41
|
+
"complexTypes": [
|
|
42
|
+
"ClearCookiesOptions"
|
|
43
|
+
],
|
|
44
|
+
"slug": "clearcookies"
|
|
37
45
|
},
|
|
38
46
|
{
|
|
39
47
|
"name": "close",
|
|
@@ -367,6 +375,36 @@
|
|
|
367
375
|
"properties": []
|
|
368
376
|
},
|
|
369
377
|
"interfaces": [
|
|
378
|
+
{
|
|
379
|
+
"name": "ClearCookiesOptions",
|
|
380
|
+
"slug": "clearcookiesoptions",
|
|
381
|
+
"docs": "",
|
|
382
|
+
"tags": [
|
|
383
|
+
{
|
|
384
|
+
"text": "0.2.0",
|
|
385
|
+
"name": "since"
|
|
386
|
+
}
|
|
387
|
+
],
|
|
388
|
+
"methods": [],
|
|
389
|
+
"properties": [
|
|
390
|
+
{
|
|
391
|
+
"name": "url",
|
|
392
|
+
"tags": [
|
|
393
|
+
{
|
|
394
|
+
"text": "'https://capawesome.io'",
|
|
395
|
+
"name": "example"
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
"text": "0.2.0",
|
|
399
|
+
"name": "since"
|
|
400
|
+
}
|
|
401
|
+
],
|
|
402
|
+
"docs": "The URL to clear the cookies for.\n\nIf not provided, all cookies are cleared.",
|
|
403
|
+
"complexTypes": [],
|
|
404
|
+
"type": "string | undefined"
|
|
405
|
+
}
|
|
406
|
+
]
|
|
407
|
+
},
|
|
370
408
|
{
|
|
371
409
|
"name": "ExecuteScriptResult",
|
|
372
410
|
"slug": "executescriptresult",
|
|
@@ -9,13 +9,16 @@ export interface InAppBrowserPlugin {
|
|
|
9
9
|
*/
|
|
10
10
|
clearCache(): Promise<void>;
|
|
11
11
|
/**
|
|
12
|
-
* Clear the
|
|
12
|
+
* Clear the cookies of the web view.
|
|
13
|
+
*
|
|
14
|
+
* Provide the `url` option to clear only the cookies of a specific URL.
|
|
15
|
+
* Otherwise, all cookies are cleared.
|
|
13
16
|
*
|
|
14
17
|
* Only available on Android and iOS.
|
|
15
18
|
*
|
|
16
|
-
* @since 0.
|
|
19
|
+
* @since 0.2.0
|
|
17
20
|
*/
|
|
18
|
-
|
|
21
|
+
clearCookies(options?: ClearCookiesOptions): Promise<void>;
|
|
19
22
|
/**
|
|
20
23
|
* Close the currently open browser.
|
|
21
24
|
*
|
|
@@ -490,6 +493,20 @@ export interface PostMessageOptions {
|
|
|
490
493
|
[key: string]: unknown;
|
|
491
494
|
};
|
|
492
495
|
}
|
|
496
|
+
/**
|
|
497
|
+
* @since 0.2.0
|
|
498
|
+
*/
|
|
499
|
+
export interface ClearCookiesOptions {
|
|
500
|
+
/**
|
|
501
|
+
* The URL to clear the cookies for.
|
|
502
|
+
*
|
|
503
|
+
* If not provided, all cookies are cleared.
|
|
504
|
+
*
|
|
505
|
+
* @example 'https://capawesome.io'
|
|
506
|
+
* @since 0.2.0
|
|
507
|
+
*/
|
|
508
|
+
url?: string;
|
|
509
|
+
}
|
|
493
510
|
/**
|
|
494
511
|
* @since 0.1.0
|
|
495
512
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AA0lBA;;GAEG;AACH,MAAM,CAAN,IAAY,SAaX;AAbD,WAAY,SAAS;IACnB;;;;OAIG;IACH,kDAAqC,CAAA;IACrC;;;;OAIG;IACH,8CAAiC,CAAA;AACnC,CAAC,EAbW,SAAS,KAAT,SAAS,QAapB","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface InAppBrowserPlugin {\n /**\n * Clear the cache of the web view.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n clearCache(): Promise<void>;\n /**\n * Clear the session data (cookies and web storage) of the web view.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n clearSessionData(): Promise<void>;\n /**\n * Close the currently open browser.\n *\n * This closes browsers opened with `openInWebView(...)` or\n * `openInSystemBrowser(...)`.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n close(): Promise<void>;\n /**\n * Execute a JavaScript script in the currently open web view.\n *\n * This method is only available for browsers opened with\n * `openInWebView(...)`.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n executeScript(options: ExecuteScriptOptions): Promise<ExecuteScriptResult>;\n /**\n * Get the cookies for a specific URL.\n *\n * On iOS, only cookies from the shared data store are returned. Cookies from\n * a web view opened with `dataStore: 'isolated'` are not included.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n getCookies(options: GetCookiesOptions): Promise<GetCookiesResult>;\n /**\n * Open a URL in the default browser app of the device.\n *\n * @since 0.1.0\n */\n openInExternalBrowser(options: OpenInExternalBrowserOptions): Promise<void>;\n /**\n * Open a URL in the system browser (Custom Tabs on Android,\n * `SFSafariViewController` on iOS).\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n openInSystemBrowser(options: OpenInSystemBrowserOptions): Promise<void>;\n /**\n * Open a URL in an embedded web view with a native toolbar.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n openInWebView(options: OpenInWebViewOptions): Promise<void>;\n /**\n * Post a message to the currently open web view.\n *\n * The web page receives the message by listening for the\n * `capacitorInAppBrowserMessage` window event. The message data is\n * available in the `detail` property of the event.\n *\n * This method is only available for browsers opened with\n * `openInWebView(...)`.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n postMessage(options: PostMessageOptions): Promise<void>;\n /**\n * Show the web view if it was opened with `visible: false`.\n *\n * This method is only available for browsers opened with\n * `openInWebView(...)`.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n show(): Promise<void>;\n /**\n * Called when the browser is closed.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n addListener(\n eventName: 'browserClosed',\n listenerFunc: () => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Called when the web page posts a message to the app using the injected\n * `window.CapacitorInAppBrowser.postMessage(...)` function.\n *\n * This event is only emitted for browsers opened with `openInWebView(...)`.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n addListener(\n eventName: 'browserMessageReceived',\n listenerFunc: (event: BrowserMessageReceivedEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Called when a page navigation has been completed in the web view.\n *\n * This event is only emitted for browsers opened with `openInWebView(...)`.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n addListener(\n eventName: 'browserNavigationCompleted',\n listenerFunc: (event: BrowserNavigationCompletedEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Called when the initial page of the browser has finished loading.\n *\n * On Android, this event is only emitted for browsers opened with\n * `openInWebView(...)`.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n addListener(\n eventName: 'browserPageLoaded',\n listenerFunc: () => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Called when the current URL of the web view changes, e.g. when the user\n * navigates to a new page, a server redirect occurs, or a single-page\n * application updates the browser history.\n *\n * This event is also emitted for the initial URL and fires earlier than\n * `browserNavigationCompleted`.\n *\n * This event is only emitted for browsers opened with `openInWebView(...)`.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n addListener(\n eventName: 'browserUrlChanged',\n listenerFunc: (event: BrowserUrlChangedEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Remove all listeners for this plugin.\n *\n * @since 0.1.0\n */\n removeAllListeners(): Promise<void>;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface OpenInExternalBrowserOptions {\n /**\n * The URL to open in the external browser.\n *\n * @example 'https://capawesome.io'\n * @since 0.1.0\n */\n url: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface OpenInSystemBrowserOptions {\n /**\n * Options that are only applied on Android.\n *\n * Only available on Android.\n *\n * @since 0.1.0\n */\n android?: OpenInSystemBrowserAndroidOptions;\n /**\n * Options that are only applied on iOS.\n *\n * Only available on iOS.\n *\n * @since 0.1.0\n */\n ios?: OpenInSystemBrowserIosOptions;\n /**\n * The URL to open in the system browser.\n *\n * @example 'https://capawesome.io'\n * @since 0.1.0\n */\n url: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface OpenInSystemBrowserAndroidOptions {\n /**\n * Whether or not the toolbar should be hidden when the user scrolls down\n * and shown when the user scrolls up.\n *\n * @default false\n * @since 0.1.0\n */\n hideToolbarOnScroll?: boolean;\n /**\n * Whether or not the title of the web page should be shown in the toolbar.\n *\n * @default false\n * @since 0.1.0\n */\n showTitle?: boolean;\n /**\n * The background color of the toolbar as a hex color code.\n *\n * @example '#008080'\n * @since 0.1.0\n */\n toolbarColor?: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface OpenInSystemBrowserIosOptions {\n /**\n * Whether or not the toolbar should collapse when the user scrolls down.\n *\n * @default true\n * @since 0.1.0\n */\n barCollapsing?: boolean;\n /**\n * The style of the dismiss button in the toolbar.\n *\n * @default 'done'\n * @since 0.1.0\n */\n dismissButtonStyle?: DismissButtonStyle;\n /**\n * Whether or not the reader mode should be entered if it is available for\n * the web page.\n *\n * @default false\n * @since 0.1.0\n */\n readerMode?: boolean;\n /**\n * The background color of the toolbar as a hex color code.\n *\n * @example '#008080'\n * @since 0.1.0\n */\n toolbarColor?: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface OpenInWebViewOptions {\n /**\n * Options that are only applied on Android.\n *\n * Only available on Android.\n *\n * @since 0.1.0\n */\n android?: OpenInWebViewAndroidOptions;\n /**\n * The data store to use for the web view.\n *\n * On Android, this option is ignored. The web view always uses the\n * app-global (`shared`) data store.\n *\n * Only available on iOS.\n *\n * @default 'shared'\n * @since 0.1.0\n */\n dataStore?: WebViewDataStore;\n /**\n * Additional HTTP headers to send with the initial request.\n *\n * @since 0.1.0\n */\n headers?: { [key: string]: string };\n /**\n * Options that are only applied on iOS.\n *\n * Only available on iOS.\n *\n * @since 0.1.0\n */\n ios?: OpenInWebViewIosOptions;\n /**\n * Whether or not media playback requires user action.\n *\n * @default false\n * @since 0.1.0\n */\n mediaPlaybackRequiresUserAction?: boolean;\n /**\n * Options for the toolbar of the web view.\n *\n * @since 0.1.0\n */\n toolbar?: WebViewToolbarOptions;\n /**\n * The URL to open in the web view.\n *\n * @example 'https://capawesome.io'\n * @since 0.1.0\n */\n url: string;\n /**\n * The custom user agent to use for the web view.\n *\n * @since 0.1.0\n */\n userAgent?: string;\n /**\n * Whether or not the web view is presented when opened.\n *\n * If `false`, the web view loads the URL in the background and stays\n * hidden until `show()` is called. The `browserPageLoaded` event is\n * still emitted and `close()` can be called while the web view is\n * hidden.\n *\n * @default true\n * @since 0.1.0\n */\n visible?: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface WebViewToolbarOptions {\n /**\n * The background color of the toolbar as a hex color code.\n *\n * @example '#008080'\n * @since 0.1.0\n */\n backgroundColor?: string;\n /**\n * The text of the close button in the toolbar.\n *\n * @default 'Close'\n * @since 0.1.0\n */\n closeButtonText?: string;\n /**\n * The text color of the toolbar as a hex color code.\n *\n * @example '#FFFFFF'\n * @since 0.1.0\n */\n color?: string;\n /**\n * Whether or not the back and forward navigation buttons should be shown\n * in the toolbar.\n *\n * @default false\n * @since 0.1.0\n */\n showNavigationButtons?: boolean;\n /**\n * Whether or not the current URL should be displayed in the toolbar\n * instead of the title.\n *\n * @default false\n * @since 0.1.0\n */\n showUrl?: boolean;\n /**\n * The fixed title to display in the toolbar.\n *\n * If not set, the title of the current web page is displayed.\n *\n * @since 0.1.0\n */\n title?: string;\n /**\n * Whether or not the toolbar should be visible.\n *\n * @default true\n * @since 0.1.0\n */\n visible?: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface OpenInWebViewAndroidOptions {\n /**\n * Whether or not the user can zoom the web page.\n *\n * @default false\n * @since 0.1.0\n */\n allowZoom?: boolean;\n /**\n * Whether or not the hardware back button navigates back in the web view's\n * history before closing the web view.\n *\n * If `false`, the hardware back button closes the web view immediately.\n *\n * @default true\n * @since 0.1.0\n */\n hardwareBackButton?: boolean;\n /**\n * Whether or not media playback is paused when the app is hidden.\n *\n * @default true\n * @since 0.1.0\n */\n pauseMediaWhenHidden?: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface OpenInWebViewIosOptions {\n /**\n * Whether or not horizontal swipe gestures navigate back and forward in\n * the web view's history.\n *\n * @default false\n * @since 0.1.0\n */\n allowsBackForwardNavigationGestures?: boolean;\n /**\n * Whether or not the web view bounces when scrolled past the edge of the\n * content.\n *\n * @default true\n * @since 0.1.0\n */\n overscroll?: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface ExecuteScriptOptions {\n /**\n * The JavaScript code to execute in the web view.\n *\n * @example 'document.title'\n * @since 0.1.0\n */\n script: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface ExecuteScriptResult {\n /**\n * The result of the script execution serialized as a JSON string.\n *\n * If the script does not return a JSON-serializable value, `null` is\n * returned.\n *\n * @example '\"Capawesome\"'\n * @since 0.1.0\n */\n result: string | null;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface PostMessageOptions {\n /**\n * The message data to post to the web view.\n *\n * Must be a JSON-serializable object.\n *\n * @example { name: 'Capawesome' }\n * @since 0.1.0\n */\n data: { [key: string]: unknown };\n}\n\n/**\n * @since 0.1.0\n */\nexport interface GetCookiesOptions {\n /**\n * The URL to get the cookies for.\n *\n * @example 'https://capawesome.io'\n * @since 0.1.0\n */\n url: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface GetCookiesResult {\n /**\n * The cookies for the URL as a map of cookie names to values.\n *\n * @since 0.1.0\n */\n cookies: { [key: string]: string };\n}\n\n/**\n * @since 0.1.0\n */\nexport interface BrowserMessageReceivedEvent {\n /**\n * The message data posted by the web page.\n *\n * @since 0.1.0\n */\n data: unknown;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface BrowserNavigationCompletedEvent {\n /**\n * The URL of the page that was navigated to.\n *\n * @example 'https://capawesome.io'\n * @since 0.1.0\n */\n url: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface BrowserUrlChangedEvent {\n /**\n * The new URL of the web view.\n *\n * @example 'https://capawesome.io'\n * @since 0.1.0\n */\n url: string;\n}\n\n/**\n * The style of the dismiss button in the toolbar of the system browser.\n *\n * - `cancel`: A button with the text \"Cancel\".\n * - `close`: A button with the text \"Close\".\n * - `done`: A button with the text \"Done\".\n *\n * @since 0.1.0\n */\nexport type DismissButtonStyle = 'cancel' | 'close' | 'done';\n\n/**\n * The data store to use for the web view.\n *\n * - `isolated`: The web view uses a non-persistent data store. Cookies and\n * web storage are discarded when the web view is closed.\n * - `shared`: The web view uses the app-global data store which is shared\n * with other web views.\n *\n * @since 0.1.0\n */\nexport type WebViewDataStore = 'isolated' | 'shared';\n\n/**\n * @since 0.1.0\n */\nexport enum ErrorCode {\n /**\n * No app was found on the device that can open the URL.\n *\n * @since 0.1.0\n */\n BrowserNotFound = 'BROWSER_NOT_FOUND',\n /**\n * No browser is currently open.\n *\n * @since 0.1.0\n */\n NoBrowserOpen = 'NO_BROWSER_OPEN',\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AA4mBA;;GAEG;AACH,MAAM,CAAN,IAAY,SAaX;AAbD,WAAY,SAAS;IACnB;;;;OAIG;IACH,kDAAqC,CAAA;IACrC;;;;OAIG;IACH,8CAAiC,CAAA;AACnC,CAAC,EAbW,SAAS,KAAT,SAAS,QAapB","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface InAppBrowserPlugin {\n /**\n * Clear the cache of the web view.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n clearCache(): Promise<void>;\n /**\n * Clear the cookies of the web view.\n *\n * Provide the `url` option to clear only the cookies of a specific URL.\n * Otherwise, all cookies are cleared.\n *\n * Only available on Android and iOS.\n *\n * @since 0.2.0\n */\n clearCookies(options?: ClearCookiesOptions): Promise<void>;\n /**\n * Close the currently open browser.\n *\n * This closes browsers opened with `openInWebView(...)` or\n * `openInSystemBrowser(...)`.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n close(): Promise<void>;\n /**\n * Execute a JavaScript script in the currently open web view.\n *\n * This method is only available for browsers opened with\n * `openInWebView(...)`.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n executeScript(options: ExecuteScriptOptions): Promise<ExecuteScriptResult>;\n /**\n * Get the cookies for a specific URL.\n *\n * On iOS, only cookies from the shared data store are returned. Cookies from\n * a web view opened with `dataStore: 'isolated'` are not included.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n getCookies(options: GetCookiesOptions): Promise<GetCookiesResult>;\n /**\n * Open a URL in the default browser app of the device.\n *\n * @since 0.1.0\n */\n openInExternalBrowser(options: OpenInExternalBrowserOptions): Promise<void>;\n /**\n * Open a URL in the system browser (Custom Tabs on Android,\n * `SFSafariViewController` on iOS).\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n openInSystemBrowser(options: OpenInSystemBrowserOptions): Promise<void>;\n /**\n * Open a URL in an embedded web view with a native toolbar.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n openInWebView(options: OpenInWebViewOptions): Promise<void>;\n /**\n * Post a message to the currently open web view.\n *\n * The web page receives the message by listening for the\n * `capacitorInAppBrowserMessage` window event. The message data is\n * available in the `detail` property of the event.\n *\n * This method is only available for browsers opened with\n * `openInWebView(...)`.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n postMessage(options: PostMessageOptions): Promise<void>;\n /**\n * Show the web view if it was opened with `visible: false`.\n *\n * This method is only available for browsers opened with\n * `openInWebView(...)`.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n show(): Promise<void>;\n /**\n * Called when the browser is closed.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n addListener(\n eventName: 'browserClosed',\n listenerFunc: () => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Called when the web page posts a message to the app using the injected\n * `window.CapacitorInAppBrowser.postMessage(...)` function.\n *\n * This event is only emitted for browsers opened with `openInWebView(...)`.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n addListener(\n eventName: 'browserMessageReceived',\n listenerFunc: (event: BrowserMessageReceivedEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Called when a page navigation has been completed in the web view.\n *\n * This event is only emitted for browsers opened with `openInWebView(...)`.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n addListener(\n eventName: 'browserNavigationCompleted',\n listenerFunc: (event: BrowserNavigationCompletedEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Called when the initial page of the browser has finished loading.\n *\n * On Android, this event is only emitted for browsers opened with\n * `openInWebView(...)`.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n addListener(\n eventName: 'browserPageLoaded',\n listenerFunc: () => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Called when the current URL of the web view changes, e.g. when the user\n * navigates to a new page, a server redirect occurs, or a single-page\n * application updates the browser history.\n *\n * This event is also emitted for the initial URL and fires earlier than\n * `browserNavigationCompleted`.\n *\n * This event is only emitted for browsers opened with `openInWebView(...)`.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n addListener(\n eventName: 'browserUrlChanged',\n listenerFunc: (event: BrowserUrlChangedEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Remove all listeners for this plugin.\n *\n * @since 0.1.0\n */\n removeAllListeners(): Promise<void>;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface OpenInExternalBrowserOptions {\n /**\n * The URL to open in the external browser.\n *\n * @example 'https://capawesome.io'\n * @since 0.1.0\n */\n url: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface OpenInSystemBrowserOptions {\n /**\n * Options that are only applied on Android.\n *\n * Only available on Android.\n *\n * @since 0.1.0\n */\n android?: OpenInSystemBrowserAndroidOptions;\n /**\n * Options that are only applied on iOS.\n *\n * Only available on iOS.\n *\n * @since 0.1.0\n */\n ios?: OpenInSystemBrowserIosOptions;\n /**\n * The URL to open in the system browser.\n *\n * @example 'https://capawesome.io'\n * @since 0.1.0\n */\n url: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface OpenInSystemBrowserAndroidOptions {\n /**\n * Whether or not the toolbar should be hidden when the user scrolls down\n * and shown when the user scrolls up.\n *\n * @default false\n * @since 0.1.0\n */\n hideToolbarOnScroll?: boolean;\n /**\n * Whether or not the title of the web page should be shown in the toolbar.\n *\n * @default false\n * @since 0.1.0\n */\n showTitle?: boolean;\n /**\n * The background color of the toolbar as a hex color code.\n *\n * @example '#008080'\n * @since 0.1.0\n */\n toolbarColor?: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface OpenInSystemBrowserIosOptions {\n /**\n * Whether or not the toolbar should collapse when the user scrolls down.\n *\n * @default true\n * @since 0.1.0\n */\n barCollapsing?: boolean;\n /**\n * The style of the dismiss button in the toolbar.\n *\n * @default 'done'\n * @since 0.1.0\n */\n dismissButtonStyle?: DismissButtonStyle;\n /**\n * Whether or not the reader mode should be entered if it is available for\n * the web page.\n *\n * @default false\n * @since 0.1.0\n */\n readerMode?: boolean;\n /**\n * The background color of the toolbar as a hex color code.\n *\n * @example '#008080'\n * @since 0.1.0\n */\n toolbarColor?: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface OpenInWebViewOptions {\n /**\n * Options that are only applied on Android.\n *\n * Only available on Android.\n *\n * @since 0.1.0\n */\n android?: OpenInWebViewAndroidOptions;\n /**\n * The data store to use for the web view.\n *\n * On Android, this option is ignored. The web view always uses the\n * app-global (`shared`) data store.\n *\n * Only available on iOS.\n *\n * @default 'shared'\n * @since 0.1.0\n */\n dataStore?: WebViewDataStore;\n /**\n * Additional HTTP headers to send with the initial request.\n *\n * @since 0.1.0\n */\n headers?: { [key: string]: string };\n /**\n * Options that are only applied on iOS.\n *\n * Only available on iOS.\n *\n * @since 0.1.0\n */\n ios?: OpenInWebViewIosOptions;\n /**\n * Whether or not media playback requires user action.\n *\n * @default false\n * @since 0.1.0\n */\n mediaPlaybackRequiresUserAction?: boolean;\n /**\n * Options for the toolbar of the web view.\n *\n * @since 0.1.0\n */\n toolbar?: WebViewToolbarOptions;\n /**\n * The URL to open in the web view.\n *\n * @example 'https://capawesome.io'\n * @since 0.1.0\n */\n url: string;\n /**\n * The custom user agent to use for the web view.\n *\n * @since 0.1.0\n */\n userAgent?: string;\n /**\n * Whether or not the web view is presented when opened.\n *\n * If `false`, the web view loads the URL in the background and stays\n * hidden until `show()` is called. The `browserPageLoaded` event is\n * still emitted and `close()` can be called while the web view is\n * hidden.\n *\n * @default true\n * @since 0.1.0\n */\n visible?: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface WebViewToolbarOptions {\n /**\n * The background color of the toolbar as a hex color code.\n *\n * @example '#008080'\n * @since 0.1.0\n */\n backgroundColor?: string;\n /**\n * The text of the close button in the toolbar.\n *\n * @default 'Close'\n * @since 0.1.0\n */\n closeButtonText?: string;\n /**\n * The text color of the toolbar as a hex color code.\n *\n * @example '#FFFFFF'\n * @since 0.1.0\n */\n color?: string;\n /**\n * Whether or not the back and forward navigation buttons should be shown\n * in the toolbar.\n *\n * @default false\n * @since 0.1.0\n */\n showNavigationButtons?: boolean;\n /**\n * Whether or not the current URL should be displayed in the toolbar\n * instead of the title.\n *\n * @default false\n * @since 0.1.0\n */\n showUrl?: boolean;\n /**\n * The fixed title to display in the toolbar.\n *\n * If not set, the title of the current web page is displayed.\n *\n * @since 0.1.0\n */\n title?: string;\n /**\n * Whether or not the toolbar should be visible.\n *\n * @default true\n * @since 0.1.0\n */\n visible?: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface OpenInWebViewAndroidOptions {\n /**\n * Whether or not the user can zoom the web page.\n *\n * @default false\n * @since 0.1.0\n */\n allowZoom?: boolean;\n /**\n * Whether or not the hardware back button navigates back in the web view's\n * history before closing the web view.\n *\n * If `false`, the hardware back button closes the web view immediately.\n *\n * @default true\n * @since 0.1.0\n */\n hardwareBackButton?: boolean;\n /**\n * Whether or not media playback is paused when the app is hidden.\n *\n * @default true\n * @since 0.1.0\n */\n pauseMediaWhenHidden?: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface OpenInWebViewIosOptions {\n /**\n * Whether or not horizontal swipe gestures navigate back and forward in\n * the web view's history.\n *\n * @default false\n * @since 0.1.0\n */\n allowsBackForwardNavigationGestures?: boolean;\n /**\n * Whether or not the web view bounces when scrolled past the edge of the\n * content.\n *\n * @default true\n * @since 0.1.0\n */\n overscroll?: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface ExecuteScriptOptions {\n /**\n * The JavaScript code to execute in the web view.\n *\n * @example 'document.title'\n * @since 0.1.0\n */\n script: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface ExecuteScriptResult {\n /**\n * The result of the script execution serialized as a JSON string.\n *\n * If the script does not return a JSON-serializable value, `null` is\n * returned.\n *\n * @example '\"Capawesome\"'\n * @since 0.1.0\n */\n result: string | null;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface PostMessageOptions {\n /**\n * The message data to post to the web view.\n *\n * Must be a JSON-serializable object.\n *\n * @example { name: 'Capawesome' }\n * @since 0.1.0\n */\n data: { [key: string]: unknown };\n}\n\n/**\n * @since 0.2.0\n */\nexport interface ClearCookiesOptions {\n /**\n * The URL to clear the cookies for.\n *\n * If not provided, all cookies are cleared.\n *\n * @example 'https://capawesome.io'\n * @since 0.2.0\n */\n url?: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface GetCookiesOptions {\n /**\n * The URL to get the cookies for.\n *\n * @example 'https://capawesome.io'\n * @since 0.1.0\n */\n url: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface GetCookiesResult {\n /**\n * The cookies for the URL as a map of cookie names to values.\n *\n * @since 0.1.0\n */\n cookies: { [key: string]: string };\n}\n\n/**\n * @since 0.1.0\n */\nexport interface BrowserMessageReceivedEvent {\n /**\n * The message data posted by the web page.\n *\n * @since 0.1.0\n */\n data: unknown;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface BrowserNavigationCompletedEvent {\n /**\n * The URL of the page that was navigated to.\n *\n * @example 'https://capawesome.io'\n * @since 0.1.0\n */\n url: string;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface BrowserUrlChangedEvent {\n /**\n * The new URL of the web view.\n *\n * @example 'https://capawesome.io'\n * @since 0.1.0\n */\n url: string;\n}\n\n/**\n * The style of the dismiss button in the toolbar of the system browser.\n *\n * - `cancel`: A button with the text \"Cancel\".\n * - `close`: A button with the text \"Close\".\n * - `done`: A button with the text \"Done\".\n *\n * @since 0.1.0\n */\nexport type DismissButtonStyle = 'cancel' | 'close' | 'done';\n\n/**\n * The data store to use for the web view.\n *\n * - `isolated`: The web view uses a non-persistent data store. Cookies and\n * web storage are discarded when the web view is closed.\n * - `shared`: The web view uses the app-global data store which is shared\n * with other web views.\n *\n * @since 0.1.0\n */\nexport type WebViewDataStore = 'isolated' | 'shared';\n\n/**\n * @since 0.1.0\n */\nexport enum ErrorCode {\n /**\n * No app was found on the device that can open the URL.\n *\n * @since 0.1.0\n */\n BrowserNotFound = 'BROWSER_NOT_FOUND',\n /**\n * No browser is currently open.\n *\n * @since 0.1.0\n */\n NoBrowserOpen = 'NO_BROWSER_OPEN',\n}\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { ExecuteScriptResult, GetCookiesResult, InAppBrowserPlugin, OpenInE
|
|
|
3
3
|
export declare class InAppBrowserWeb extends WebPlugin implements InAppBrowserPlugin {
|
|
4
4
|
private static errorUrlMissing;
|
|
5
5
|
clearCache(): Promise<void>;
|
|
6
|
-
|
|
6
|
+
clearCookies(): Promise<void>;
|
|
7
7
|
close(): Promise<void>;
|
|
8
8
|
executeScript(): Promise<ExecuteScriptResult>;
|
|
9
9
|
getCookies(): Promise<GetCookiesResult>;
|
package/dist/esm/web.js
CHANGED
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAS5C,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAG5C,KAAK,CAAC,UAAU;QACd,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAS5C,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAG5C,KAAK,CAAC,UAAU;QACd,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,UAAU;QACd,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,qBAAqB,CACzB,OAAqC;QAErC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;QACnD,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,mBAAmB;QACvB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,WAAW;QACf,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,CAAC;;AA7Cc,+BAAe,GAAG,uBAAuB,CAAC","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n ExecuteScriptResult,\n GetCookiesResult,\n InAppBrowserPlugin,\n OpenInExternalBrowserOptions,\n} from './definitions';\n\nexport class InAppBrowserWeb extends WebPlugin implements InAppBrowserPlugin {\n private static errorUrlMissing = 'url must be provided.';\n\n async clearCache(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async clearCookies(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async close(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async executeScript(): Promise<ExecuteScriptResult> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async getCookies(): Promise<GetCookiesResult> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async openInExternalBrowser(\n options: OpenInExternalBrowserOptions,\n ): Promise<void> {\n if (!options.url) {\n throw new Error(InAppBrowserWeb.errorUrlMissing);\n }\n window.open(options.url, '_blank');\n }\n\n async openInSystemBrowser(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async openInWebView(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async postMessage(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async show(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -29,7 +29,7 @@ class InAppBrowserWeb extends core.WebPlugin {
|
|
|
29
29
|
async clearCache() {
|
|
30
30
|
throw this.unimplemented('Not implemented on web.');
|
|
31
31
|
}
|
|
32
|
-
async
|
|
32
|
+
async clearCookies() {
|
|
33
33
|
throw this.unimplemented('Not implemented on web.');
|
|
34
34
|
}
|
|
35
35
|
async close() {
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * @since 0.1.0\n */\nexport var ErrorCode;\n(function (ErrorCode) {\n /**\n * No app was found on the device that can open the URL.\n *\n * @since 0.1.0\n */\n ErrorCode[\"BrowserNotFound\"] = \"BROWSER_NOT_FOUND\";\n /**\n * No browser is currently open.\n *\n * @since 0.1.0\n */\n ErrorCode[\"NoBrowserOpen\"] = \"NO_BROWSER_OPEN\";\n})(ErrorCode || (ErrorCode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst InAppBrowser = registerPlugin('InAppBrowser', {\n web: () => import('./web').then(m => new m.InAppBrowserWeb()),\n});\nexport * from './definitions';\nexport { InAppBrowser };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class InAppBrowserWeb extends WebPlugin {\n async clearCache() {\n throw this.unimplemented('Not implemented on web.');\n }\n async
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * @since 0.1.0\n */\nexport var ErrorCode;\n(function (ErrorCode) {\n /**\n * No app was found on the device that can open the URL.\n *\n * @since 0.1.0\n */\n ErrorCode[\"BrowserNotFound\"] = \"BROWSER_NOT_FOUND\";\n /**\n * No browser is currently open.\n *\n * @since 0.1.0\n */\n ErrorCode[\"NoBrowserOpen\"] = \"NO_BROWSER_OPEN\";\n})(ErrorCode || (ErrorCode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst InAppBrowser = registerPlugin('InAppBrowser', {\n web: () => import('./web').then(m => new m.InAppBrowserWeb()),\n});\nexport * from './definitions';\nexport { InAppBrowser };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class InAppBrowserWeb extends WebPlugin {\n async clearCache() {\n throw this.unimplemented('Not implemented on web.');\n }\n async clearCookies() {\n throw this.unimplemented('Not implemented on web.');\n }\n async close() {\n throw this.unimplemented('Not implemented on web.');\n }\n async executeScript() {\n throw this.unimplemented('Not implemented on web.');\n }\n async getCookies() {\n throw this.unimplemented('Not implemented on web.');\n }\n async openInExternalBrowser(options) {\n if (!options.url) {\n throw new Error(InAppBrowserWeb.errorUrlMissing);\n }\n window.open(options.url, '_blank');\n }\n async openInSystemBrowser() {\n throw this.unimplemented('Not implemented on web.');\n }\n async openInWebView() {\n throw this.unimplemented('Not implemented on web.');\n }\n async postMessage() {\n throw this.unimplemented('Not implemented on web.');\n }\n async show() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\nInAppBrowserWeb.errorUrlMissing = 'url must be provided.';\n//# sourceMappingURL=web.js.map"],"names":["ErrorCode","registerPlugin","WebPlugin"],"mappings":";;;;AAAA;AACA;AACA;AACWA;AACX,CAAC,UAAU,SAAS,EAAE;AACtB;AACA;AACA;AACA;AACA;AACA,IAAI,SAAS,CAAC,iBAAiB,CAAC,GAAG,mBAAmB;AACtD;AACA;AACA;AACA;AACA;AACA,IAAI,SAAS,CAAC,eAAe,CAAC,GAAG,iBAAiB;AAClD,CAAC,EAAEA,iBAAS,KAAKA,iBAAS,GAAG,EAAE,CAAC,CAAC;;AChB5B,MAAC,YAAY,GAAGC,mBAAc,CAAC,cAAc,EAAE;AACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;AACjE,CAAC;;ACFM,MAAM,eAAe,SAASC,cAAS,CAAC;AAC/C,IAAI,MAAM,UAAU,GAAG;AACvB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,YAAY,GAAG;AACzB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,KAAK,GAAG;AAClB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,aAAa,GAAG;AAC1B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,UAAU,GAAG;AACvB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,qBAAqB,CAAC,OAAO,EAAE;AACzC,QAAQ,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE;AAC1B,YAAY,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,eAAe,CAAC;AAC5D,QAAQ;AACR,QAAQ,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC;AAC1C,IAAI;AACJ,IAAI,MAAM,mBAAmB,GAAG;AAChC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,aAAa,GAAG;AAC1B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ;AACA,eAAe,CAAC,eAAe,GAAG,uBAAuB;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -28,7 +28,7 @@ var capacitorInAppBrowser = (function (exports, core) {
|
|
|
28
28
|
async clearCache() {
|
|
29
29
|
throw this.unimplemented('Not implemented on web.');
|
|
30
30
|
}
|
|
31
|
-
async
|
|
31
|
+
async clearCookies() {
|
|
32
32
|
throw this.unimplemented('Not implemented on web.');
|
|
33
33
|
}
|
|
34
34
|
async close() {
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * @since 0.1.0\n */\nexport var ErrorCode;\n(function (ErrorCode) {\n /**\n * No app was found on the device that can open the URL.\n *\n * @since 0.1.0\n */\n ErrorCode[\"BrowserNotFound\"] = \"BROWSER_NOT_FOUND\";\n /**\n * No browser is currently open.\n *\n * @since 0.1.0\n */\n ErrorCode[\"NoBrowserOpen\"] = \"NO_BROWSER_OPEN\";\n})(ErrorCode || (ErrorCode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst InAppBrowser = registerPlugin('InAppBrowser', {\n web: () => import('./web').then(m => new m.InAppBrowserWeb()),\n});\nexport * from './definitions';\nexport { InAppBrowser };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class InAppBrowserWeb extends WebPlugin {\n async clearCache() {\n throw this.unimplemented('Not implemented on web.');\n }\n async
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/**\n * @since 0.1.0\n */\nexport var ErrorCode;\n(function (ErrorCode) {\n /**\n * No app was found on the device that can open the URL.\n *\n * @since 0.1.0\n */\n ErrorCode[\"BrowserNotFound\"] = \"BROWSER_NOT_FOUND\";\n /**\n * No browser is currently open.\n *\n * @since 0.1.0\n */\n ErrorCode[\"NoBrowserOpen\"] = \"NO_BROWSER_OPEN\";\n})(ErrorCode || (ErrorCode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst InAppBrowser = registerPlugin('InAppBrowser', {\n web: () => import('./web').then(m => new m.InAppBrowserWeb()),\n});\nexport * from './definitions';\nexport { InAppBrowser };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class InAppBrowserWeb extends WebPlugin {\n async clearCache() {\n throw this.unimplemented('Not implemented on web.');\n }\n async clearCookies() {\n throw this.unimplemented('Not implemented on web.');\n }\n async close() {\n throw this.unimplemented('Not implemented on web.');\n }\n async executeScript() {\n throw this.unimplemented('Not implemented on web.');\n }\n async getCookies() {\n throw this.unimplemented('Not implemented on web.');\n }\n async openInExternalBrowser(options) {\n if (!options.url) {\n throw new Error(InAppBrowserWeb.errorUrlMissing);\n }\n window.open(options.url, '_blank');\n }\n async openInSystemBrowser() {\n throw this.unimplemented('Not implemented on web.');\n }\n async openInWebView() {\n throw this.unimplemented('Not implemented on web.');\n }\n async postMessage() {\n throw this.unimplemented('Not implemented on web.');\n }\n async show() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\nInAppBrowserWeb.errorUrlMissing = 'url must be provided.';\n//# sourceMappingURL=web.js.map"],"names":["ErrorCode","registerPlugin","WebPlugin"],"mappings":";;;IAAA;IACA;IACA;AACWA;IACX,CAAC,UAAU,SAAS,EAAE;IACtB;IACA;IACA;IACA;IACA;IACA,IAAI,SAAS,CAAC,iBAAiB,CAAC,GAAG,mBAAmB;IACtD;IACA;IACA;IACA;IACA;IACA,IAAI,SAAS,CAAC,eAAe,CAAC,GAAG,iBAAiB;IAClD,CAAC,EAAEA,iBAAS,KAAKA,iBAAS,GAAG,EAAE,CAAC,CAAC;;AChB5B,UAAC,YAAY,GAAGC,mBAAc,CAAC,cAAc,EAAE;IACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;IACjE,CAAC;;ICFM,MAAM,eAAe,SAASC,cAAS,CAAC;IAC/C,IAAI,MAAM,UAAU,GAAG;IACvB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,YAAY,GAAG;IACzB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,KAAK,GAAG;IAClB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,aAAa,GAAG;IAC1B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,UAAU,GAAG;IACvB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,qBAAqB,CAAC,OAAO,EAAE;IACzC,QAAQ,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE;IAC1B,YAAY,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,eAAe,CAAC;IAC5D,QAAQ;IACR,QAAQ,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC;IAC1C,IAAI;IACJ,IAAI,MAAM,mBAAmB,GAAG;IAChC,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,aAAa,GAAG;IAC1B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,WAAW,GAAG;IACxB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,IAAI,GAAG;IACjB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ;IACA,eAAe,CAAC,eAAe,GAAG,uBAAuB;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
@objc public class ClearCookiesOptions: NSObject {
|
|
5
|
+
let url: URL?
|
|
6
|
+
|
|
7
|
+
init(_ call: CAPPluginCall) throws {
|
|
8
|
+
self.url = try ClearCookiesOptions.getUrlFromCall(call)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
private static func getUrlFromCall(_ call: CAPPluginCall) throws -> URL? {
|
|
12
|
+
guard let urlString = call.getString("url"), !urlString.isEmpty else {
|
|
13
|
+
return nil
|
|
14
|
+
}
|
|
15
|
+
guard let url = URL(string: urlString) else {
|
|
16
|
+
throw CustomError.urlInvalid
|
|
17
|
+
}
|
|
18
|
+
return url
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -24,11 +24,30 @@ import WebKit
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
@objc public func
|
|
27
|
+
@objc public func clearCookies(_ options: ClearCookiesOptions, completion: @escaping (_ error: Error?) -> Void) {
|
|
28
28
|
DispatchQueue.main.async {
|
|
29
|
-
let
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
let dataStore = WKWebsiteDataStore.default()
|
|
30
|
+
guard let url = options.url else {
|
|
31
|
+
dataStore.removeData(ofTypes: [WKWebsiteDataTypeCookies], modifiedSince: .distantPast) {
|
|
32
|
+
completion(nil)
|
|
33
|
+
}
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
let cookieStore = dataStore.httpCookieStore
|
|
37
|
+
cookieStore.getAllCookies { cookies in
|
|
38
|
+
let cookiesToDelete = cookies.filter { cookie in
|
|
39
|
+
InAppBrowserHelper.isCookie(cookie, matchingURL: url)
|
|
40
|
+
}
|
|
41
|
+
let dispatchGroup = DispatchGroup()
|
|
42
|
+
for cookie in cookiesToDelete {
|
|
43
|
+
dispatchGroup.enter()
|
|
44
|
+
cookieStore.delete(cookie) {
|
|
45
|
+
dispatchGroup.leave()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
dispatchGroup.notify(queue: .main) {
|
|
49
|
+
completion(nil)
|
|
50
|
+
}
|
|
32
51
|
}
|
|
33
52
|
}
|
|
34
53
|
}
|
|
@@ -7,7 +7,7 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
7
7
|
public let jsName = "InAppBrowser"
|
|
8
8
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
9
9
|
CAPPluginMethod(name: "clearCache", returnType: CAPPluginReturnPromise),
|
|
10
|
-
CAPPluginMethod(name: "
|
|
10
|
+
CAPPluginMethod(name: "clearCookies", returnType: CAPPluginReturnPromise),
|
|
11
11
|
CAPPluginMethod(name: "close", returnType: CAPPluginReturnPromise),
|
|
12
12
|
CAPPluginMethod(name: "executeScript", returnType: CAPPluginReturnPromise),
|
|
13
13
|
CAPPluginMethod(name: "getCookies", returnType: CAPPluginReturnPromise),
|
|
@@ -37,14 +37,20 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
37
37
|
})
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
@objc func
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
@objc func clearCookies(_ call: CAPPluginCall) {
|
|
41
|
+
do {
|
|
42
|
+
let options = try ClearCookiesOptions(call)
|
|
43
|
+
|
|
44
|
+
implementation?.clearCookies(options, completion: { error in
|
|
45
|
+
if let error = error {
|
|
46
|
+
self.rejectCall(call, error)
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
self.resolveCall(call)
|
|
50
|
+
})
|
|
51
|
+
} catch {
|
|
52
|
+
rejectCall(call, error)
|
|
53
|
+
}
|
|
48
54
|
}
|
|
49
55
|
|
|
50
56
|
@objc func close(_ call: CAPPluginCall) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capawesome/capacitor-in-app-browser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
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",
|
|
@@ -67,15 +67,15 @@
|
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@capacitor/android": "8.0.0",
|
|
70
|
-
"@capacitor/cli": "8.
|
|
70
|
+
"@capacitor/cli": "8.4.2",
|
|
71
71
|
"@capacitor/core": "8.0.0",
|
|
72
72
|
"@capacitor/docgen": "0.3.1",
|
|
73
73
|
"@capacitor/ios": "8.0.0",
|
|
74
74
|
"@ionic/eslint-config": "0.4.0",
|
|
75
75
|
"eslint": "8.57.0",
|
|
76
|
-
"prettier-plugin-java": "2.
|
|
76
|
+
"prettier-plugin-java": "2.9.7",
|
|
77
77
|
"rimraf": "6.1.2",
|
|
78
|
-
"rollup": "4.
|
|
78
|
+
"rollup": "4.62.3",
|
|
79
79
|
"swiftlint": "2.0.0",
|
|
80
80
|
"typescript": "5.9.3"
|
|
81
81
|
},
|