@capgo/inappbrowser 7.1.1 → 7.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 +45 -5
- package/android/build.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +0 -1
- package/android/src/main/java/ee/forgr/capacitor_inappbrowser/InAppBrowserPlugin.java +0 -4
- package/android/src/main/java/ee/forgr/capacitor_inappbrowser/WebViewDialog.java +32 -2
- package/dist/docs.json +2 -2
- package/dist/esm/definitions.d.ts +4 -4
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Plugin/InAppBrowserPlugin.swift +7 -3
- package/ios/Plugin/WKWebViewController.swift +13 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<h2><a href="https://capgo.app/consulting/?ref=plugin"> Fix your annoying bug now, Hire a Capacitor expert 💪</a></h2>
|
|
7
7
|
</div>
|
|
8
8
|
|
|
9
|
-
Capacitor plugin in app browser with urlChangeEvent
|
|
9
|
+
Capacitor plugin in app browser with urlChangeEvent, two way communication, camera and microphone usage, etc.
|
|
10
10
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
@@ -69,6 +69,46 @@ Add the following to your `Info.plist` file:
|
|
|
69
69
|
<string>We need access to the microphone to record audio.</string>
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
+
### Two way communication
|
|
73
|
+
|
|
74
|
+
With this plugin you can send events from the main app to the inappbrowser and vice versa.
|
|
75
|
+
|
|
76
|
+
> The data is sent as a JSON object, so no functions or other non-JSON-serializable types are allowed.
|
|
77
|
+
|
|
78
|
+
#### Main app to inappbrowser
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
InAppBrowser.postMessage({ detail: { message: "myMessage" } });
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### Receive event from native in the inappbrowser
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
window.addListener("messageFromNative", (event) => {
|
|
88
|
+
console.log(event);
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
#### Send event from inappbrowser to main app
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
window.mobileApp.postMessage({ detail: { message: "myMessage" } });
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### Receive event from inappbrowser in the main app
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
window.addListener("messageFromWebview", (event) => {
|
|
102
|
+
console.log(event);
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Close inappbrowser from inappbrowser itself
|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
window.mobileApp.close();
|
|
110
|
+
```
|
|
111
|
+
|
|
72
112
|
## API
|
|
73
113
|
|
|
74
114
|
<docgen-index>
|
|
@@ -239,7 +279,7 @@ Injects JavaScript code into the InAppBrowser window.
|
|
|
239
279
|
postMessage(options: { detail: Record<string, any>; }) => Promise<void>
|
|
240
280
|
```
|
|
241
281
|
|
|
242
|
-
Sends an event to the webview. you can listen to this event with addListener("
|
|
282
|
+
Sends an event to the webview(inappbrowser). you can listen to this event in the inappbrowser JS with window.addListener("messageFromNative", listenerFunc: (event: <a href="#record">Record</a><string, any>) => void)
|
|
243
283
|
detail is the data you want to send to the webview, it's a requirement of Capacitor we cannot send direct objects
|
|
244
284
|
Your object has to be serializable to JSON, so no functions or other non-JSON-serializable types are allowed.
|
|
245
285
|
|
|
@@ -349,9 +389,9 @@ Will be triggered when user clicks on confirm button when disclaimer is required
|
|
|
349
389
|
addListener(eventName: "messageFromWebview", listenerFunc: (event: { detail: Record<string, any>; }) => void) => Promise<PluginListenerHandle>
|
|
350
390
|
```
|
|
351
391
|
|
|
352
|
-
Will be triggered when event is sent from webview, to send an event to the
|
|
353
|
-
detail is the data you want to send to the
|
|
354
|
-
Your object has to be serializable to JSON,
|
|
392
|
+
Will be triggered when event is sent from webview(inappbrowser), to send an event to the main app use window.mobileApp.postMessage({ "detail": { "message": "myMessage" } })
|
|
393
|
+
detail is the data you want to send to the main app, it's a requirement of Capacitor we cannot send direct objects
|
|
394
|
+
Your object has to be serializable to JSON, no functions or other non-JSON-serializable types are allowed.
|
|
355
395
|
|
|
356
396
|
This method is inject at runtime in the webview
|
|
357
397
|
|
package/android/build.gradle
CHANGED
|
@@ -54,6 +54,7 @@ dependencies {
|
|
|
54
54
|
implementation project(':capacitor-android')
|
|
55
55
|
implementation 'com.caverock:androidsvg:1.4'
|
|
56
56
|
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
57
|
+
implementation "androidx.window:window:1.3.0"
|
|
57
58
|
testImplementation "junit:junit:$junitVersion"
|
|
58
59
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
59
60
|
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
@@ -45,10 +45,6 @@ import org.json.JSONObject;
|
|
|
45
45
|
alias = "storage",
|
|
46
46
|
strings = { Manifest.permission.READ_EXTERNAL_STORAGE }
|
|
47
47
|
),
|
|
48
|
-
@Permission(
|
|
49
|
-
alias = "storage",
|
|
50
|
-
strings = { Manifest.permission.READ_MEDIA_IMAGES }
|
|
51
|
-
),
|
|
52
48
|
},
|
|
53
49
|
requestCodes = { WebViewDialog.FILE_CHOOSER_REQUEST_CODE }
|
|
54
50
|
)
|
|
@@ -38,6 +38,7 @@ import android.widget.TextView;
|
|
|
38
38
|
import android.widget.Toast;
|
|
39
39
|
import android.widget.Toolbar;
|
|
40
40
|
import androidx.annotation.RequiresApi;
|
|
41
|
+
import androidx.core.view.WindowInsetsControllerCompat;
|
|
41
42
|
import com.caverock.androidsvg.SVG;
|
|
42
43
|
import com.caverock.androidsvg.SVGParseException;
|
|
43
44
|
import com.getcapacitor.JSObject;
|
|
@@ -132,6 +133,21 @@ public class WebViewDialog extends Dialog {
|
|
|
132
133
|
// Handle message from JavaScript
|
|
133
134
|
_options.getCallbacks().javascriptCallback(message);
|
|
134
135
|
}
|
|
136
|
+
|
|
137
|
+
@JavascriptInterface
|
|
138
|
+
public void close() {
|
|
139
|
+
// close webview
|
|
140
|
+
activity.runOnUiThread(
|
|
141
|
+
new Runnable() {
|
|
142
|
+
@Override
|
|
143
|
+
public void run() {
|
|
144
|
+
dismiss();
|
|
145
|
+
_options.getCallbacks().closeEvent(_webView.getUrl());
|
|
146
|
+
_webView.destroy();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
}
|
|
135
151
|
}
|
|
136
152
|
|
|
137
153
|
public class PreShowScriptInterface {
|
|
@@ -163,6 +179,17 @@ public class WebViewDialog extends Dialog {
|
|
|
163
179
|
WindowManager.LayoutParams.FLAG_FULLSCREEN
|
|
164
180
|
);
|
|
165
181
|
setContentView(R.layout.activity_browser);
|
|
182
|
+
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
183
|
+
|
|
184
|
+
WindowInsetsControllerCompat insetsController =
|
|
185
|
+
new WindowInsetsControllerCompat(getWindow(), getWindow().getDecorView());
|
|
186
|
+
insetsController.setAppearanceLightStatusBars(false);
|
|
187
|
+
getWindow()
|
|
188
|
+
.getDecorView()
|
|
189
|
+
.post(() -> {
|
|
190
|
+
getWindow().setStatusBarColor(Color.BLACK);
|
|
191
|
+
});
|
|
192
|
+
|
|
166
193
|
getWindow()
|
|
167
194
|
.setLayout(
|
|
168
195
|
WindowManager.LayoutParams.MATCH_PARENT,
|
|
@@ -318,6 +345,9 @@ public class WebViewDialog extends Dialog {
|
|
|
318
345
|
" if (window.AndroidInterface) { " +
|
|
319
346
|
" window.AndroidInterface.postMessage(JSON.stringify(message)); " +
|
|
320
347
|
" } " +
|
|
348
|
+
" }, " +
|
|
349
|
+
" close: function() { " +
|
|
350
|
+
" window.AndroidInterface.close(); " +
|
|
321
351
|
" } " +
|
|
322
352
|
" }; " +
|
|
323
353
|
"}";
|
|
@@ -487,7 +517,7 @@ public class WebViewDialog extends Dialog {
|
|
|
487
517
|
}
|
|
488
518
|
);
|
|
489
519
|
|
|
490
|
-
|
|
520
|
+
ImageButton closeButton = _toolbar.findViewById(R.id.closeButton);
|
|
491
521
|
closeButton.setOnClickListener(
|
|
492
522
|
new View.OnClickListener() {
|
|
493
523
|
@Override
|
|
@@ -520,7 +550,7 @@ public class WebViewDialog extends Dialog {
|
|
|
520
550
|
);
|
|
521
551
|
|
|
522
552
|
if (_options.showArrow()) {
|
|
523
|
-
closeButton.
|
|
553
|
+
closeButton.setImageResource(R.drawable.arrow_back_enabled);
|
|
524
554
|
}
|
|
525
555
|
|
|
526
556
|
if (_options.getShowReloadButton()) {
|
package/dist/docs.json
CHANGED
|
@@ -170,7 +170,7 @@
|
|
|
170
170
|
],
|
|
171
171
|
"returns": "Promise<void>",
|
|
172
172
|
"tags": [],
|
|
173
|
-
"docs": "Sends an event to the webview. you can listen to this event with addListener(\"
|
|
173
|
+
"docs": "Sends an event to the webview(inappbrowser). you can listen to this event in the inappbrowser JS with window.addListener(\"messageFromNative\", listenerFunc: (event: Record<string, any>) => void)\ndetail is the data you want to send to the webview, it's a requirement of Capacitor we cannot send direct objects\nYour object has to be serializable to JSON, so no functions or other non-JSON-serializable types are allowed.",
|
|
174
174
|
"complexTypes": [
|
|
175
175
|
"Record"
|
|
176
176
|
],
|
|
@@ -320,7 +320,7 @@
|
|
|
320
320
|
],
|
|
321
321
|
"returns": "Promise<PluginListenerHandle>",
|
|
322
322
|
"tags": [],
|
|
323
|
-
"docs": "Will be triggered when event is sent from webview, to send an event to the
|
|
323
|
+
"docs": "Will be triggered when event is sent from webview(inappbrowser), to send an event to the main app use window.mobileApp.postMessage({ \"detail\": { \"message\": \"myMessage\" } })\ndetail is the data you want to send to the main app, it's a requirement of Capacitor we cannot send direct objects\nYour object has to be serializable to JSON, no functions or other non-JSON-serializable types are allowed.\n\nThis method is inject at runtime in the webview",
|
|
324
324
|
"complexTypes": [
|
|
325
325
|
"PluginListenerHandle",
|
|
326
326
|
"Record"
|
|
@@ -296,7 +296,7 @@ export interface InAppBrowserPlugin {
|
|
|
296
296
|
code: string;
|
|
297
297
|
}): Promise<void>;
|
|
298
298
|
/**
|
|
299
|
-
* Sends an event to the webview. you can listen to this event with addListener("
|
|
299
|
+
* Sends an event to the webview(inappbrowser). you can listen to this event in the inappbrowser JS with window.addListener("messageFromNative", listenerFunc: (event: Record<string, any>) => void)
|
|
300
300
|
* detail is the data you want to send to the webview, it's a requirement of Capacitor we cannot send direct objects
|
|
301
301
|
* Your object has to be serializable to JSON, so no functions or other non-JSON-serializable types are allowed.
|
|
302
302
|
*/
|
|
@@ -329,9 +329,9 @@ export interface InAppBrowserPlugin {
|
|
|
329
329
|
*/
|
|
330
330
|
addListener(eventName: "confirmBtnClicked", listenerFunc: ConfirmBtnListener): Promise<PluginListenerHandle>;
|
|
331
331
|
/**
|
|
332
|
-
* Will be triggered when event is sent from webview, to send an event to the
|
|
333
|
-
* detail is the data you want to send to the
|
|
334
|
-
* Your object has to be serializable to JSON,
|
|
332
|
+
* Will be triggered when event is sent from webview(inappbrowser), to send an event to the main app use window.mobileApp.postMessage({ "detail": { "message": "myMessage" } })
|
|
333
|
+
* detail is the data you want to send to the main app, it's a requirement of Capacitor we cannot send direct objects
|
|
334
|
+
* Your object has to be serializable to JSON, no functions or other non-JSON-serializable types are allowed.
|
|
335
335
|
*
|
|
336
336
|
* This method is inject at runtime in the webview
|
|
337
337
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAuBA,MAAM,CAAN,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,kCAAe,CAAA;IACf,kCAAe,CAAA;AACjB,CAAC,EAHW,eAAe,KAAf,eAAe,QAG1B;AACD,MAAM,CAAN,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,oCAAqB,CAAA;IACrB,wCAAyB,CAAA;IACzB,8BAAe,CAAA;IACf,2BAAY,CAAA;AACd,CAAC,EALW,WAAW,KAAX,WAAW,QAKtB","sourcesContent":["import type { PluginListenerHandle } from \"@capacitor/core\";\n\nexport interface UrlEvent {\n /**\n * Emit when the url changes\n *\n * @since 0.0.1\n */\n url: string;\n}\nexport interface BtnEvent {\n /**\n * Emit when a button is clicked.\n *\n * @since 0.0.1\n */\n url: string;\n}\n\nexport type UrlChangeListener = (state: UrlEvent) => void;\nexport type ConfirmBtnListener = (state: BtnEvent) => void;\nexport type ButtonNearListener = (state: {}) => void;\n\nexport enum BackgroundColor {\n WHITE = \"white\",\n BLACK = \"black\",\n}\nexport enum ToolBarType {\n ACTIVITY = \"activity\",\n NAVIGATION = \"navigation\",\n BLANK = \"blank\",\n DEFAULT = \"\",\n}\n\nexport interface Headers {\n [key: string]: string;\n}\n\nexport interface GetCookieOptions {\n url: string;\n includeHttpOnly?: boolean;\n}\n\nexport interface ClearCookieOptions {\n url: string;\n}\n\nexport interface Credentials {\n username: string;\n password: string;\n}\n\nexport interface OpenOptions {\n /**\n * Target URL to load.\n * @since 0.1.0\n */\n url: string;\n /**\n * Headers to send with the request.\n * @since 0.1.0\n */\n headers?: Headers;\n /**\n * Credentials to send with the request and all subsequent requests for the same host.\n * @since 6.1.0\n */\n credentials?: Credentials;\n /**\n * if true, the browser will be presented after the page is loaded, if false, the browser will be presented immediately.\n * @since 0.1.0\n */\n isPresentAfterPageLoad?: boolean;\n preventDeeplink?: boolean;\n}\n\nexport interface DisclaimerOptions {\n title: string;\n message: string;\n confirmBtn: string;\n cancelBtn: string;\n}\n\nexport interface OpenWebViewOptions {\n /**\n * Target URL to load.\n * @since 0.1.0\n */\n url: string;\n /**\n * Headers to send with the request.\n * @since 0.1.0\n */\n headers?: Headers;\n /**\n * Credentials to send with the request and all subsequent requests for the same host.\n * @since 6.1.0\n */\n credentials?: Credentials;\n /**\n * share options\n * @since 0.1.0\n */\n shareDisclaimer?: DisclaimerOptions;\n /**\n * Toolbar type\n * @since 0.1.0\n * @default ToolBarType.DEFAULT\n */\n toolbarType?: ToolBarType;\n /**\n * Share subject\n * @since 0.1.0\n */\n shareSubject?: string;\n /**\n * Title of the browser\n * @since 0.1.0\n * @default 'New Window'\n */\n title?: string;\n /**\n * Background color of the browser, only on IOS\n * @since 0.1.0\n * @default BackgroundColor.BLACK\n */\n backgroundColor?: BackgroundColor;\n /**\n * If true, active the native navigation within the webview, Android only\n *\n * @default false\n */\n activeNativeNavigationForWebview?: boolean;\n /**\n * Disable the possibility to go back on native application,\n * usefull to force user to stay on the webview, Android only\n *\n * @default false\n */\n disableGoBackOnNativeApplication?: boolean;\n /**\n * Open url in a new window fullscreen\n *\n * isPresentAfterPageLoad: if true, the browser will be presented after the page is loaded, if false, the browser will be presented immediately.\n * @since 0.1.0\n * @default false\n */\n isPresentAfterPageLoad?: boolean;\n /**\n * Whether the website in the webview is inspectable or not, ios only\n *\n * @default false\n */\n isInspectable?: boolean;\n /**\n * Whether the webview opening is animated or not, ios only\n *\n * @default true\n */\n isAnimated?: boolean;\n /**\n * Shows a reload button that reloads the web page\n * @since 1.0.15\n * @default false\n */\n showReloadButton?: boolean;\n /**\n * CloseModal: if true a confirm will be displayed when user clicks on close button, if false the browser will be closed immediately.\n *\n * @since 1.1.0\n * @default false\n */\n closeModal?: boolean;\n /**\n * CloseModalTitle: title of the confirm when user clicks on close button, only on IOS\n *\n * @since 1.1.0\n * @default 'Close'\n */\n closeModalTitle?: string;\n /**\n * CloseModalDescription: description of the confirm when user clicks on close button, only on IOS\n *\n * @since 1.1.0\n * @default 'Are you sure you want to close this window?'\n */\n closeModalDescription?: string;\n /**\n * CloseModalOk: text of the confirm button when user clicks on close button, only on IOS\n *\n * @since 1.1.0\n * @default 'Close'\n */\n closeModalOk?: string;\n /**\n * CloseModalCancel: text of the cancel button when user clicks on close button, only on IOS\n *\n * @since 1.1.0\n * @default 'Cancel'\n */\n closeModalCancel?: string;\n /**\n * visibleTitle: if true the website title would be shown else shown empty\n *\n * @since 1.2.5\n * @default true\n */\n visibleTitle?: boolean;\n /**\n * toolbarColor: color of the toolbar in hex format\n *\n * @since 1.2.5\n * @default '#ffffff''\n */\n toolbarColor?: string;\n /**\n * showArrow: if true an arrow would be shown instead of cross for closing the window\n *\n * @since 1.2.5\n * @default false\n */\n showArrow?: boolean;\n /**\n * ignoreUntrustedSSLError: if true, the webview will ignore untrusted SSL errors allowing the user to view the website.\n *\n * @since 6.1.0\n * @default false\n */\n ignoreUntrustedSSLError?: boolean;\n /**\n * preShowScript: if isPresentAfterPageLoad is true and this variable is set the plugin will inject a script before showing the browser.\n * This script will be run in an async context. The plugin will wait for the script to finish (max 10 seconds)\n *\n * @since 6.6.0\n */\n preShowScript?: String;\n /**\n * proxyRequests is a regex expression. Please see [this pr](https://github.com/Cap-go/capacitor-inappbrowser/pull/222) for more info. (Android only)\n *\n * @since 6.9.0\n */\n proxyRequests?: String;\n /**\n * buttonNearDone allows for a creation of a custom button. Please see [buttonNearDone.md](/buttonNearDone.md) for more info.\n *\n * @since 6.7.0\n */\n buttonNearDone?: {\n ios: {\n iconType: \"sf-symbol\" | \"asset\";\n icon: String;\n };\n android: {\n iconType: \"asset\";\n icon: String;\n width?: number;\n height?: number;\n };\n };\n}\n\nexport interface InAppBrowserPlugin {\n /**\n * Open url in a new window fullscreen\n *\n * @since 0.1.0\n */\n open(options: OpenOptions): Promise<any>;\n\n /**\n * Clear cookies of url\n *\n * @since 0.5.0\n */\n clearCookies(options: ClearCookieOptions): Promise<any>;\n /**\n * Clear all cookies\n *\n * @since 6.5.0\n */\n clearAllCookies(): Promise<any>;\n\n /**\n * Clear cache\n *\n * @since 6.5.0\n */\n clearCache(): Promise<any>;\n\n /**\n * Get cookies for a specific URL.\n * @param options The options, including the URL to get cookies for.\n * @returns A promise that resolves with the cookies.\n */\n getCookies(options: GetCookieOptions): Promise<Record<string, string>>;\n /**\n * Close the webview.\n */\n close(): Promise<any>;\n /**\n * Open url in a new webview with toolbars, and enhanced capabilities, like camera access, file access, listen events, inject javascript, bi directional communication, etc.\n *\n * @since 0.1.0\n */\n openWebView(options: OpenWebViewOptions): Promise<any>;\n /**\n * Injects JavaScript code into the InAppBrowser window.\n */\n executeScript({ code }: { code: string }): Promise<void>;\n /**\n * Sends an event to the webview. you can listen to this event with addListener(\"messageFromWebview\", listenerFunc: (event: Record<string, any>) => void)\n * detail is the data you want to send to the webview, it's a requirement of Capacitor we cannot send direct objects\n * Your object has to be serializable to JSON, so no functions or other non-JSON-serializable types are allowed.\n */\n postMessage(options: { detail: Record<string, any> }): Promise<void>;\n /**\n * Sets the URL of the webview.\n */\n setUrl(options: { url: string }): Promise<any>;\n /**\n * Listen for url change, only for openWebView\n *\n * @since 0.0.1\n */\n addListener(\n eventName: \"urlChangeEvent\",\n listenerFunc: UrlChangeListener,\n ): Promise<PluginListenerHandle>;\n\n addListener(\n eventName: \"buttonNearDoneClick\",\n listenerFunc: ButtonNearListener,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Listen for close click only for openWebView\n *\n * @since 0.4.0\n */\n addListener(\n eventName: \"closeEvent\",\n listenerFunc: UrlChangeListener,\n ): Promise<PluginListenerHandle>;\n /**\n * Will be triggered when user clicks on confirm button when disclaimer is required, works only on iOS\n *\n * @since 0.0.1\n */\n addListener(\n eventName: \"confirmBtnClicked\",\n listenerFunc: ConfirmBtnListener,\n ): Promise<PluginListenerHandle>;\n /**\n * Will be triggered when event is sent from webview, to send an event to the webview use window.mobileApp.postMessage({ \"detail\": { \"message\": \"myMessage\" } })\n * detail is the data you want to send to the webview, it's a requirement of Capacitor we cannot send direct objects\n * Your object has to be serializable to JSON, so no functions or other non-JSON-serializable types are allowed.\n *\n * This method is inject at runtime in the webview\n */\n addListener(\n eventName: \"messageFromWebview\",\n listenerFunc: (event: { detail: Record<string, any> }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Will be triggered when page is loaded\n */\n addListener(\n eventName: \"browserPageLoaded\",\n listenerFunc: () => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Will be triggered when page load error\n */\n addListener(\n eventName: \"pageLoadError\",\n listenerFunc: () => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Remove all listeners for this plugin.\n *\n * @since 1.0.0\n */\n removeAllListeners(): Promise<void>;\n\n /**\n * Reload the current web page.\n *\n * @since 1.0.0\n */\n reload(): Promise<any>; // Add this line\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAuBA,MAAM,CAAN,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,kCAAe,CAAA;IACf,kCAAe,CAAA;AACjB,CAAC,EAHW,eAAe,KAAf,eAAe,QAG1B;AACD,MAAM,CAAN,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,oCAAqB,CAAA;IACrB,wCAAyB,CAAA;IACzB,8BAAe,CAAA;IACf,2BAAY,CAAA;AACd,CAAC,EALW,WAAW,KAAX,WAAW,QAKtB","sourcesContent":["import type { PluginListenerHandle } from \"@capacitor/core\";\n\nexport interface UrlEvent {\n /**\n * Emit when the url changes\n *\n * @since 0.0.1\n */\n url: string;\n}\nexport interface BtnEvent {\n /**\n * Emit when a button is clicked.\n *\n * @since 0.0.1\n */\n url: string;\n}\n\nexport type UrlChangeListener = (state: UrlEvent) => void;\nexport type ConfirmBtnListener = (state: BtnEvent) => void;\nexport type ButtonNearListener = (state: {}) => void;\n\nexport enum BackgroundColor {\n WHITE = \"white\",\n BLACK = \"black\",\n}\nexport enum ToolBarType {\n ACTIVITY = \"activity\",\n NAVIGATION = \"navigation\",\n BLANK = \"blank\",\n DEFAULT = \"\",\n}\n\nexport interface Headers {\n [key: string]: string;\n}\n\nexport interface GetCookieOptions {\n url: string;\n includeHttpOnly?: boolean;\n}\n\nexport interface ClearCookieOptions {\n url: string;\n}\n\nexport interface Credentials {\n username: string;\n password: string;\n}\n\nexport interface OpenOptions {\n /**\n * Target URL to load.\n * @since 0.1.0\n */\n url: string;\n /**\n * Headers to send with the request.\n * @since 0.1.0\n */\n headers?: Headers;\n /**\n * Credentials to send with the request and all subsequent requests for the same host.\n * @since 6.1.0\n */\n credentials?: Credentials;\n /**\n * if true, the browser will be presented after the page is loaded, if false, the browser will be presented immediately.\n * @since 0.1.0\n */\n isPresentAfterPageLoad?: boolean;\n preventDeeplink?: boolean;\n}\n\nexport interface DisclaimerOptions {\n title: string;\n message: string;\n confirmBtn: string;\n cancelBtn: string;\n}\n\nexport interface OpenWebViewOptions {\n /**\n * Target URL to load.\n * @since 0.1.0\n */\n url: string;\n /**\n * Headers to send with the request.\n * @since 0.1.0\n */\n headers?: Headers;\n /**\n * Credentials to send with the request and all subsequent requests for the same host.\n * @since 6.1.0\n */\n credentials?: Credentials;\n /**\n * share options\n * @since 0.1.0\n */\n shareDisclaimer?: DisclaimerOptions;\n /**\n * Toolbar type\n * @since 0.1.0\n * @default ToolBarType.DEFAULT\n */\n toolbarType?: ToolBarType;\n /**\n * Share subject\n * @since 0.1.0\n */\n shareSubject?: string;\n /**\n * Title of the browser\n * @since 0.1.0\n * @default 'New Window'\n */\n title?: string;\n /**\n * Background color of the browser, only on IOS\n * @since 0.1.0\n * @default BackgroundColor.BLACK\n */\n backgroundColor?: BackgroundColor;\n /**\n * If true, active the native navigation within the webview, Android only\n *\n * @default false\n */\n activeNativeNavigationForWebview?: boolean;\n /**\n * Disable the possibility to go back on native application,\n * usefull to force user to stay on the webview, Android only\n *\n * @default false\n */\n disableGoBackOnNativeApplication?: boolean;\n /**\n * Open url in a new window fullscreen\n *\n * isPresentAfterPageLoad: if true, the browser will be presented after the page is loaded, if false, the browser will be presented immediately.\n * @since 0.1.0\n * @default false\n */\n isPresentAfterPageLoad?: boolean;\n /**\n * Whether the website in the webview is inspectable or not, ios only\n *\n * @default false\n */\n isInspectable?: boolean;\n /**\n * Whether the webview opening is animated or not, ios only\n *\n * @default true\n */\n isAnimated?: boolean;\n /**\n * Shows a reload button that reloads the web page\n * @since 1.0.15\n * @default false\n */\n showReloadButton?: boolean;\n /**\n * CloseModal: if true a confirm will be displayed when user clicks on close button, if false the browser will be closed immediately.\n *\n * @since 1.1.0\n * @default false\n */\n closeModal?: boolean;\n /**\n * CloseModalTitle: title of the confirm when user clicks on close button, only on IOS\n *\n * @since 1.1.0\n * @default 'Close'\n */\n closeModalTitle?: string;\n /**\n * CloseModalDescription: description of the confirm when user clicks on close button, only on IOS\n *\n * @since 1.1.0\n * @default 'Are you sure you want to close this window?'\n */\n closeModalDescription?: string;\n /**\n * CloseModalOk: text of the confirm button when user clicks on close button, only on IOS\n *\n * @since 1.1.0\n * @default 'Close'\n */\n closeModalOk?: string;\n /**\n * CloseModalCancel: text of the cancel button when user clicks on close button, only on IOS\n *\n * @since 1.1.0\n * @default 'Cancel'\n */\n closeModalCancel?: string;\n /**\n * visibleTitle: if true the website title would be shown else shown empty\n *\n * @since 1.2.5\n * @default true\n */\n visibleTitle?: boolean;\n /**\n * toolbarColor: color of the toolbar in hex format\n *\n * @since 1.2.5\n * @default '#ffffff''\n */\n toolbarColor?: string;\n /**\n * showArrow: if true an arrow would be shown instead of cross for closing the window\n *\n * @since 1.2.5\n * @default false\n */\n showArrow?: boolean;\n /**\n * ignoreUntrustedSSLError: if true, the webview will ignore untrusted SSL errors allowing the user to view the website.\n *\n * @since 6.1.0\n * @default false\n */\n ignoreUntrustedSSLError?: boolean;\n /**\n * preShowScript: if isPresentAfterPageLoad is true and this variable is set the plugin will inject a script before showing the browser.\n * This script will be run in an async context. The plugin will wait for the script to finish (max 10 seconds)\n *\n * @since 6.6.0\n */\n preShowScript?: String;\n /**\n * proxyRequests is a regex expression. Please see [this pr](https://github.com/Cap-go/capacitor-inappbrowser/pull/222) for more info. (Android only)\n *\n * @since 6.9.0\n */\n proxyRequests?: String;\n /**\n * buttonNearDone allows for a creation of a custom button. Please see [buttonNearDone.md](/buttonNearDone.md) for more info.\n *\n * @since 6.7.0\n */\n buttonNearDone?: {\n ios: {\n iconType: \"sf-symbol\" | \"asset\";\n icon: String;\n };\n android: {\n iconType: \"asset\";\n icon: String;\n width?: number;\n height?: number;\n };\n };\n}\n\nexport interface InAppBrowserPlugin {\n /**\n * Open url in a new window fullscreen\n *\n * @since 0.1.0\n */\n open(options: OpenOptions): Promise<any>;\n\n /**\n * Clear cookies of url\n *\n * @since 0.5.0\n */\n clearCookies(options: ClearCookieOptions): Promise<any>;\n /**\n * Clear all cookies\n *\n * @since 6.5.0\n */\n clearAllCookies(): Promise<any>;\n\n /**\n * Clear cache\n *\n * @since 6.5.0\n */\n clearCache(): Promise<any>;\n\n /**\n * Get cookies for a specific URL.\n * @param options The options, including the URL to get cookies for.\n * @returns A promise that resolves with the cookies.\n */\n getCookies(options: GetCookieOptions): Promise<Record<string, string>>;\n /**\n * Close the webview.\n */\n close(): Promise<any>;\n /**\n * Open url in a new webview with toolbars, and enhanced capabilities, like camera access, file access, listen events, inject javascript, bi directional communication, etc.\n *\n * @since 0.1.0\n */\n openWebView(options: OpenWebViewOptions): Promise<any>;\n /**\n * Injects JavaScript code into the InAppBrowser window.\n */\n executeScript({ code }: { code: string }): Promise<void>;\n /**\n * Sends an event to the webview(inappbrowser). you can listen to this event in the inappbrowser JS with window.addListener(\"messageFromNative\", listenerFunc: (event: Record<string, any>) => void)\n * detail is the data you want to send to the webview, it's a requirement of Capacitor we cannot send direct objects\n * Your object has to be serializable to JSON, so no functions or other non-JSON-serializable types are allowed.\n */\n postMessage(options: { detail: Record<string, any> }): Promise<void>;\n /**\n * Sets the URL of the webview.\n */\n setUrl(options: { url: string }): Promise<any>;\n /**\n * Listen for url change, only for openWebView\n *\n * @since 0.0.1\n */\n addListener(\n eventName: \"urlChangeEvent\",\n listenerFunc: UrlChangeListener,\n ): Promise<PluginListenerHandle>;\n\n addListener(\n eventName: \"buttonNearDoneClick\",\n listenerFunc: ButtonNearListener,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Listen for close click only for openWebView\n *\n * @since 0.4.0\n */\n addListener(\n eventName: \"closeEvent\",\n listenerFunc: UrlChangeListener,\n ): Promise<PluginListenerHandle>;\n /**\n * Will be triggered when user clicks on confirm button when disclaimer is required, works only on iOS\n *\n * @since 0.0.1\n */\n addListener(\n eventName: \"confirmBtnClicked\",\n listenerFunc: ConfirmBtnListener,\n ): Promise<PluginListenerHandle>;\n /**\n * Will be triggered when event is sent from webview(inappbrowser), to send an event to the main app use window.mobileApp.postMessage({ \"detail\": { \"message\": \"myMessage\" } })\n * detail is the data you want to send to the main app, it's a requirement of Capacitor we cannot send direct objects\n * Your object has to be serializable to JSON, no functions or other non-JSON-serializable types are allowed.\n *\n * This method is inject at runtime in the webview\n */\n addListener(\n eventName: \"messageFromWebview\",\n listenerFunc: (event: { detail: Record<string, any> }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Will be triggered when page is loaded\n */\n addListener(\n eventName: \"browserPageLoaded\",\n listenerFunc: () => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Will be triggered when page load error\n */\n addListener(\n eventName: \"pageLoadError\",\n listenerFunc: () => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Remove all listeners for this plugin.\n *\n * @since 1.0.0\n */\n removeAllListeners(): Promise<void>;\n\n /**\n * Reload the current web page.\n *\n * @since 1.0.0\n */\n reload(): Promise<any>; // Add this line\n}\n"]}
|
|
@@ -289,8 +289,10 @@ public class InAppBrowserPlugin: CAPPlugin {
|
|
|
289
289
|
call.reject("Cannot get script to execute")
|
|
290
290
|
return
|
|
291
291
|
}
|
|
292
|
-
|
|
293
|
-
|
|
292
|
+
DispatchQueue.main.async {
|
|
293
|
+
self.webViewController?.executeScript(script: script)
|
|
294
|
+
call.resolve()
|
|
295
|
+
}
|
|
294
296
|
}
|
|
295
297
|
|
|
296
298
|
@objc func postMessage(_ call: CAPPluginCall) {
|
|
@@ -302,7 +304,9 @@ public class InAppBrowserPlugin: CAPPlugin {
|
|
|
302
304
|
}
|
|
303
305
|
print("Event data: \(eventData)")
|
|
304
306
|
|
|
305
|
-
|
|
307
|
+
DispatchQueue.main.async {
|
|
308
|
+
self.webViewController?.postMessageToJS(message: eventData)
|
|
309
|
+
}
|
|
306
310
|
call.resolve()
|
|
307
311
|
}
|
|
308
312
|
|
|
@@ -239,7 +239,9 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
239
239
|
if let jsonData = try? JSONSerialization.data(withJSONObject: message, options: []),
|
|
240
240
|
let jsonString = String(data: jsonData, encoding: .utf8) {
|
|
241
241
|
let script = "window.dispatchEvent(new CustomEvent('messageFromNative', { detail: \(jsonString) }));"
|
|
242
|
-
|
|
242
|
+
DispatchQueue.main.async {
|
|
243
|
+
self.webView?.evaluateJavaScript(script, completionHandler: nil)
|
|
244
|
+
}
|
|
243
245
|
}
|
|
244
246
|
}
|
|
245
247
|
|
|
@@ -267,6 +269,8 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
267
269
|
}
|
|
268
270
|
print("[InAppBrowser - preShowScriptError]: Error!!!!")
|
|
269
271
|
semaphore.signal()
|
|
272
|
+
} else if message.name == "close" {
|
|
273
|
+
closeView()
|
|
270
274
|
}
|
|
271
275
|
}
|
|
272
276
|
|
|
@@ -278,6 +282,9 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
278
282
|
if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.messageHandler) {
|
|
279
283
|
window.webkit.messageHandlers.messageHandler.postMessage(message);
|
|
280
284
|
}
|
|
285
|
+
},
|
|
286
|
+
close: function() {
|
|
287
|
+
window.webkit.messageHandlers.close.postMessage(null);
|
|
281
288
|
}
|
|
282
289
|
};
|
|
283
290
|
}
|
|
@@ -299,6 +306,8 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
299
306
|
userContentController.add(self, name: "messageHandler")
|
|
300
307
|
userContentController.add(self, name: "preShowScriptError")
|
|
301
308
|
userContentController.add(self, name: "preShowScriptSuccess")
|
|
309
|
+
userContentController.add(self, name: "close")
|
|
310
|
+
webConfiguration.allowsInlineMediaPlayback = true
|
|
302
311
|
webConfiguration.userContentController = userContentController
|
|
303
312
|
let webView = WKWebView(frame: .zero, configuration: webConfiguration)
|
|
304
313
|
|
|
@@ -842,9 +851,11 @@ extension WKWebViewController: WKUIDelegate {
|
|
|
842
851
|
// Ensure UI updates are on the main thread
|
|
843
852
|
DispatchQueue.main.async {
|
|
844
853
|
let alertController = UIAlertController(title: nil, message: message, preferredStyle: .alert)
|
|
854
|
+
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: { _ in
|
|
855
|
+
completionHandler()
|
|
856
|
+
}))
|
|
845
857
|
self.present(alertController, animated: true, completion: nil)
|
|
846
858
|
}
|
|
847
|
-
completionHandler()
|
|
848
859
|
}
|
|
849
860
|
}
|
|
850
861
|
|