@capgo/inappbrowser 6.4.0-beta.2 → 6.4.3
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 +17 -11
- package/android/src/main/java/ee/forgr/capacitor_inappbrowser/InAppBrowserPlugin.java +1 -1
- package/android/src/main/java/ee/forgr/capacitor_inappbrowser/WebViewDialog.java +11 -9
- package/dist/docs.json +6 -6
- package/dist/esm/definitions.d.ts +14 -4
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Plugin/InAppBrowserPlugin.swift +1 -1
- package/ios/Plugin/WKWebViewController.swift +0 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -198,14 +198,16 @@ Injects JavaScript code into the InAppBrowser window.
|
|
|
198
198
|
### postMessage(...)
|
|
199
199
|
|
|
200
200
|
```typescript
|
|
201
|
-
postMessage(options: Record<string, any
|
|
201
|
+
postMessage(options: { detail: Record<string, any>; }) => Promise<void>
|
|
202
202
|
```
|
|
203
203
|
|
|
204
|
-
Sends an event to the webview.
|
|
204
|
+
Sends an event to the webview. you can listen to this event with addListener("messageFromWebview", listenerFunc: (event: <a href="#record">Record</a><string, any>) => void)
|
|
205
|
+
detail is the data you want to send to the webview, it's a requirement of Capacitor we cannot send direct objects
|
|
206
|
+
Your object has to be serializable to JSON, so no functions or other non-JSON-serializable types are allowed.
|
|
205
207
|
|
|
206
|
-
| Param | Type
|
|
207
|
-
| ------------- |
|
|
208
|
-
| **`options`** | <code
|
|
208
|
+
| Param | Type |
|
|
209
|
+
| ------------- | ------------------------------------------------------------------------- |
|
|
210
|
+
| **`options`** | <code>{ detail: <a href="#record">Record</a><string, any>; }</code> |
|
|
209
211
|
|
|
210
212
|
--------------------
|
|
211
213
|
|
|
@@ -290,15 +292,19 @@ Will be triggered when user clicks on confirm button when disclaimer is required
|
|
|
290
292
|
### addListener('messageFromWebview', ...)
|
|
291
293
|
|
|
292
294
|
```typescript
|
|
293
|
-
addListener(eventName: "messageFromWebview", listenerFunc: (event: Record<string, any
|
|
295
|
+
addListener(eventName: "messageFromWebview", listenerFunc: (event: { detail: Record<string, any>; }) => void) => Promise<PluginListenerHandle>
|
|
294
296
|
```
|
|
295
297
|
|
|
296
|
-
Will be triggered when event is sent from webview
|
|
298
|
+
Will be triggered when event is sent from webview, to send an event to the webview use window.mobileApp.postMessage({ "detail": { "message": "myMessage" } })
|
|
299
|
+
detail is the data you want to send to the webview, it's a requirement of Capacitor we cannot send direct objects
|
|
300
|
+
Your object has to be serializable to JSON, so no functions or other non-JSON-serializable types are allowed.
|
|
297
301
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
|
301
|
-
|
|
|
302
|
+
This method is inject at runtime in the webview
|
|
303
|
+
|
|
304
|
+
| Param | Type |
|
|
305
|
+
| ------------------ | --------------------------------------------------------------------------------------------- |
|
|
306
|
+
| **`eventName`** | <code>'messageFromWebview'</code> |
|
|
307
|
+
| **`listenerFunc`** | <code>(event: { detail: <a href="#record">Record</a><string, any>; }) => void</code> |
|
|
302
308
|
|
|
303
309
|
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
304
310
|
|
|
@@ -458,7 +458,7 @@ public class InAppBrowserPlugin
|
|
|
458
458
|
call.reject("WebView is not initialized");
|
|
459
459
|
return;
|
|
460
460
|
}
|
|
461
|
-
JSObject eventData = call.getObject("
|
|
461
|
+
JSObject eventData = call.getObject("detail");
|
|
462
462
|
// Log event data
|
|
463
463
|
Log.d("InAppBrowserPlugin", "Event data: " + eventData.toString());
|
|
464
464
|
if (eventData == null) {
|
|
@@ -32,16 +32,14 @@ import android.widget.TextView;
|
|
|
32
32
|
import android.widget.Toast;
|
|
33
33
|
import android.widget.Toolbar;
|
|
34
34
|
import com.getcapacitor.JSObject;
|
|
35
|
-
|
|
36
|
-
import org.json.JSONArray;
|
|
37
|
-
import org.json.JSONObject;
|
|
38
|
-
|
|
39
35
|
import java.net.URI;
|
|
40
36
|
import java.net.URISyntaxException;
|
|
41
37
|
import java.util.HashMap;
|
|
42
38
|
import java.util.Iterator;
|
|
43
39
|
import java.util.Map;
|
|
44
40
|
import java.util.Objects;
|
|
41
|
+
import org.json.JSONArray;
|
|
42
|
+
import org.json.JSONObject;
|
|
45
43
|
|
|
46
44
|
public class WebViewDialog extends Dialog {
|
|
47
45
|
|
|
@@ -221,10 +219,16 @@ public class WebViewDialog extends Dialog {
|
|
|
221
219
|
JSONObject jsonObject = new JSONObject();
|
|
222
220
|
jsonObject.put("detail", detail);
|
|
223
221
|
String jsonDetail = jsonObject.toString();
|
|
224
|
-
String script =
|
|
222
|
+
String script =
|
|
223
|
+
"window.dispatchEvent(new CustomEvent('messageFromNative', " +
|
|
224
|
+
jsonDetail +
|
|
225
|
+
"));";
|
|
225
226
|
_webView.post(() -> _webView.evaluateJavascript(script, null));
|
|
226
227
|
} catch (Exception e) {
|
|
227
|
-
Log.e(
|
|
228
|
+
Log.e(
|
|
229
|
+
"postMessageToJS",
|
|
230
|
+
"Error sending message to JS: " + e.getMessage()
|
|
231
|
+
);
|
|
228
232
|
}
|
|
229
233
|
}
|
|
230
234
|
}
|
|
@@ -234,9 +238,7 @@ public class WebViewDialog extends Dialog {
|
|
|
234
238
|
"if (!window.mobileApp) { " +
|
|
235
239
|
" window.mobileApp = { " +
|
|
236
240
|
" postMessage: function(message) { " +
|
|
237
|
-
" if (window.
|
|
238
|
-
" window.webkit.messageHandlers.messageHandler.postMessage(message); " +
|
|
239
|
-
" } else if (window.AndroidInterface) { " +
|
|
241
|
+
" if (window.AndroidInterface) { " +
|
|
240
242
|
" window.AndroidInterface.postMessage(JSON.stringify(message)); " +
|
|
241
243
|
" } " +
|
|
242
244
|
" } " +
|
package/dist/docs.json
CHANGED
|
@@ -130,17 +130,17 @@
|
|
|
130
130
|
},
|
|
131
131
|
{
|
|
132
132
|
"name": "postMessage",
|
|
133
|
-
"signature": "(options: Record<string, any
|
|
133
|
+
"signature": "(options: { detail: Record<string, any>; }) => Promise<void>",
|
|
134
134
|
"parameters": [
|
|
135
135
|
{
|
|
136
136
|
"name": "options",
|
|
137
137
|
"docs": "",
|
|
138
|
-
"type": "Record<string, any
|
|
138
|
+
"type": "{ detail: Record<string, any>; }"
|
|
139
139
|
}
|
|
140
140
|
],
|
|
141
141
|
"returns": "Promise<void>",
|
|
142
142
|
"tags": [],
|
|
143
|
-
"docs": "Sends an event to the webview.",
|
|
143
|
+
"docs": "Sends an event to the webview. you can listen to this event with addListener(\"messageFromWebview\", 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.",
|
|
144
144
|
"complexTypes": [
|
|
145
145
|
"Record"
|
|
146
146
|
],
|
|
@@ -251,7 +251,7 @@
|
|
|
251
251
|
},
|
|
252
252
|
{
|
|
253
253
|
"name": "addListener",
|
|
254
|
-
"signature": "(eventName: \"messageFromWebview\", listenerFunc: (event: Record<string, any
|
|
254
|
+
"signature": "(eventName: \"messageFromWebview\", listenerFunc: (event: { detail: Record<string, any>; }) => void) => Promise<PluginListenerHandle>",
|
|
255
255
|
"parameters": [
|
|
256
256
|
{
|
|
257
257
|
"name": "eventName",
|
|
@@ -261,12 +261,12 @@
|
|
|
261
261
|
{
|
|
262
262
|
"name": "listenerFunc",
|
|
263
263
|
"docs": "",
|
|
264
|
-
"type": "(event: Record<string, any
|
|
264
|
+
"type": "(event: { detail: Record<string, any>; }) => void"
|
|
265
265
|
}
|
|
266
266
|
],
|
|
267
267
|
"returns": "Promise<PluginListenerHandle>",
|
|
268
268
|
"tags": [],
|
|
269
|
-
"docs": "Will be triggered when event is sent from webview",
|
|
269
|
+
"docs": "Will be triggered when event is sent from webview, to send an event to the webview use window.mobileApp.postMessage({ \"detail\": { \"message\": \"myMessage\" } })\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.\n\nThis method is inject at runtime in the webview",
|
|
270
270
|
"complexTypes": [
|
|
271
271
|
"PluginListenerHandle",
|
|
272
272
|
"Record"
|
|
@@ -254,9 +254,13 @@ export interface InAppBrowserPlugin {
|
|
|
254
254
|
code: string;
|
|
255
255
|
}): Promise<void>;
|
|
256
256
|
/**
|
|
257
|
-
* Sends an event to the webview.
|
|
257
|
+
* Sends an event to the webview. you can listen to this event with addListener("messageFromWebview", listenerFunc: (event: Record<string, any>) => void)
|
|
258
|
+
* detail is the data you want to send to the webview, it's a requirement of Capacitor we cannot send direct objects
|
|
259
|
+
* Your object has to be serializable to JSON, so no functions or other non-JSON-serializable types are allowed.
|
|
258
260
|
*/
|
|
259
|
-
postMessage(options:
|
|
261
|
+
postMessage(options: {
|
|
262
|
+
detail: Record<string, any>;
|
|
263
|
+
}): Promise<void>;
|
|
260
264
|
/**
|
|
261
265
|
* Sets the URL of the webview.
|
|
262
266
|
*/
|
|
@@ -282,9 +286,15 @@ export interface InAppBrowserPlugin {
|
|
|
282
286
|
*/
|
|
283
287
|
addListener(eventName: "confirmBtnClicked", listenerFunc: ConfirmBtnListener): Promise<PluginListenerHandle>;
|
|
284
288
|
/**
|
|
285
|
-
* Will be triggered when event is sent from webview
|
|
289
|
+
* Will be triggered when event is sent from webview, to send an event to the webview use window.mobileApp.postMessage({ "detail": { "message": "myMessage" } })
|
|
290
|
+
* detail is the data you want to send to the webview, it's a requirement of Capacitor we cannot send direct objects
|
|
291
|
+
* Your object has to be serializable to JSON, so no functions or other non-JSON-serializable types are allowed.
|
|
292
|
+
*
|
|
293
|
+
* This method is inject at runtime in the webview
|
|
286
294
|
*/
|
|
287
|
-
addListener(eventName: "messageFromWebview", listenerFunc: (event:
|
|
295
|
+
addListener(eventName: "messageFromWebview", listenerFunc: (event: {
|
|
296
|
+
detail: Record<string, any>;
|
|
297
|
+
}) => void): Promise<PluginListenerHandle>;
|
|
288
298
|
/**
|
|
289
299
|
* Will be triggered when page is loaded
|
|
290
300
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAsBA,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;\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 cache?: boolean;\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\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 /**\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\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.\n */\n postMessage(options: 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 /**\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\n */\n addListener(\n eventName: \"messageFromWebview\",\n listenerFunc: (event: 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 is loaded\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":"AAsBA,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;\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 cache?: boolean;\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\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 /**\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\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 /**\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 is loaded\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"]}
|
|
@@ -234,7 +234,7 @@ public class InAppBrowserPlugin: CAPPlugin {
|
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
@objc func postMessage(_ call: CAPPluginCall) {
|
|
237
|
-
let eventData = call.getObject("
|
|
237
|
+
let eventData = call.getObject("detail", [:])
|
|
238
238
|
// Check if eventData is empty
|
|
239
239
|
if eventData.isEmpty {
|
|
240
240
|
call.reject("Event data must not be empty")
|
|
@@ -251,8 +251,6 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
251
251
|
postMessage: function(message) {
|
|
252
252
|
if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.messageHandler) {
|
|
253
253
|
window.webkit.messageHandlers.messageHandler.postMessage(message);
|
|
254
|
-
} else if (window.AndroidInterface) {
|
|
255
|
-
window.AndroidInterface.postMessage(JSON.stringify(message));
|
|
256
254
|
}
|
|
257
255
|
}
|
|
258
256
|
};
|
|
@@ -807,7 +805,6 @@ extension WKWebViewController: WKNavigationDelegate {
|
|
|
807
805
|
self.url = u
|
|
808
806
|
delegate?.webViewController?(self, didStart: u)
|
|
809
807
|
}
|
|
810
|
-
self.injectJavaScriptInterface()
|
|
811
808
|
}
|
|
812
809
|
public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
|
|
813
810
|
if !didpageInit && self.capBrowserPlugin?.isPresentAfterPageLoad == true {
|
|
@@ -831,7 +828,6 @@ extension WKWebViewController: WKNavigationDelegate {
|
|
|
831
828
|
self.url = url
|
|
832
829
|
delegate?.webViewController?(self, didFail: url, withError: error)
|
|
833
830
|
}
|
|
834
|
-
self.injectJavaScriptInterface()
|
|
835
831
|
self.capBrowserPlugin?.notifyListeners("pageLoadError", data: [:])
|
|
836
832
|
}
|
|
837
833
|
|
|
@@ -842,7 +838,6 @@ extension WKWebViewController: WKNavigationDelegate {
|
|
|
842
838
|
self.url = url
|
|
843
839
|
delegate?.webViewController?(self, didFail: url, withError: error)
|
|
844
840
|
}
|
|
845
|
-
self.injectJavaScriptInterface()
|
|
846
841
|
self.capBrowserPlugin?.notifyListeners("pageLoadError", data: [:])
|
|
847
842
|
}
|
|
848
843
|
|