@capgo/inappbrowser 6.9.38 → 6.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -99
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/ee/forgr/capacitor_inappbrowser/WebViewDialog.java +34 -2
- package/dist/docs.json +9 -636
- package/dist/esm/definitions.d.ts +9 -9
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Plugin/InAppBrowserPlugin.swift +26 -6
- package/ios/Plugin/WKWebViewController.swift +48 -7
- package/package.json +1 -1
- package/ios/Plugin/InAppBrowserPlugin.h +0 -10
- package/ios/Plugin/InAppBrowserPlugin.m +0 -21
|
@@ -17,7 +17,7 @@ export interface BtnEvent {
|
|
|
17
17
|
}
|
|
18
18
|
export type UrlChangeListener = (state: UrlEvent) => void;
|
|
19
19
|
export type ConfirmBtnListener = (state: BtnEvent) => void;
|
|
20
|
-
export type ButtonNearListener = (state:
|
|
20
|
+
export type ButtonNearListener = (state: object) => void;
|
|
21
21
|
export declare enum BackgroundColor {
|
|
22
22
|
WHITE = "white",
|
|
23
23
|
BLACK = "black"
|
|
@@ -223,13 +223,13 @@ export interface OpenWebViewOptions {
|
|
|
223
223
|
*
|
|
224
224
|
* @since 6.6.0
|
|
225
225
|
*/
|
|
226
|
-
preShowScript?:
|
|
226
|
+
preShowScript?: string;
|
|
227
227
|
/**
|
|
228
228
|
* proxyRequests is a regex expression. Please see [this pr](https://github.com/Cap-go/capacitor-inappbrowser/pull/222) for more info. (Android only)
|
|
229
229
|
*
|
|
230
230
|
* @since 6.9.0
|
|
231
231
|
*/
|
|
232
|
-
proxyRequests?:
|
|
232
|
+
proxyRequests?: string;
|
|
233
233
|
/**
|
|
234
234
|
* buttonNearDone allows for a creation of a custom button. Please see [buttonNearDone.md](/buttonNearDone.md) for more info.
|
|
235
235
|
*
|
|
@@ -238,11 +238,11 @@ export interface OpenWebViewOptions {
|
|
|
238
238
|
buttonNearDone?: {
|
|
239
239
|
ios: {
|
|
240
240
|
iconType: "sf-symbol" | "asset";
|
|
241
|
-
icon:
|
|
241
|
+
icon: string;
|
|
242
242
|
};
|
|
243
243
|
android: {
|
|
244
244
|
iconType: "asset";
|
|
245
|
-
icon:
|
|
245
|
+
icon: string;
|
|
246
246
|
width?: number;
|
|
247
247
|
height?: number;
|
|
248
248
|
};
|
|
@@ -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: object) => 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"]}
|
|
@@ -23,7 +23,23 @@ extension UIColor {
|
|
|
23
23
|
* here: https://capacitorjs.com/docs/plugins/ios
|
|
24
24
|
*/
|
|
25
25
|
@objc(InAppBrowserPlugin)
|
|
26
|
-
public class InAppBrowserPlugin: CAPPlugin {
|
|
26
|
+
public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
27
|
+
public let identifier = "InAppBrowserPlugin"
|
|
28
|
+
public let jsName = "InAppBrowser"
|
|
29
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
30
|
+
CAPPluginMethod(name: "open", returnType: CAPPluginReturnPromise),
|
|
31
|
+
CAPPluginMethod(name: "openWebView", returnType: CAPPluginReturnPromise),
|
|
32
|
+
CAPPluginMethod(name: "clearCookies", returnType: CAPPluginReturnPromise),
|
|
33
|
+
CAPPluginMethod(name: "getCookies", returnType: CAPPluginReturnPromise),
|
|
34
|
+
CAPPluginMethod(name: "clearAllCookies", returnType: CAPPluginReturnPromise),
|
|
35
|
+
CAPPluginMethod(name: "clearCache", returnType: CAPPluginReturnPromise),
|
|
36
|
+
CAPPluginMethod(name: "reload", returnType: CAPPluginReturnPromise),
|
|
37
|
+
CAPPluginMethod(name: "setUrl", returnType: CAPPluginReturnPromise),
|
|
38
|
+
CAPPluginMethod(name: "show", returnType: CAPPluginReturnPromise),
|
|
39
|
+
CAPPluginMethod(name: "close", returnType: CAPPluginReturnPromise),
|
|
40
|
+
CAPPluginMethod(name: "executeScript", returnType: CAPPluginReturnPromise),
|
|
41
|
+
CAPPluginMethod(name: "postMessage", returnType: CAPPluginReturnPromise)
|
|
42
|
+
]
|
|
27
43
|
var navigationWebViewController: UINavigationController?
|
|
28
44
|
private var privacyScreen: UIImageView?
|
|
29
45
|
private var isSetupDone = false
|
|
@@ -196,9 +212,8 @@ public class InAppBrowserPlugin: CAPPlugin {
|
|
|
196
212
|
|
|
197
213
|
DispatchQueue.main.async {
|
|
198
214
|
let url = URL(string: urlString)
|
|
199
|
-
|
|
200
215
|
if self.isPresentAfterPageLoad {
|
|
201
|
-
self.webViewController = WKWebViewController.init(url: url!, headers: headers, isInspectable: isInspectable, credentials: credentials, preventDeeplink: preventDeeplink)
|
|
216
|
+
self.webViewController = WKWebViewController.init(url: url!, headers: headers, isInspectable: isInspectable, credentials: credentials, preventDeeplink: preventDeeplink, blankNavigationTab: toolbarType == "blank")
|
|
202
217
|
} else {
|
|
203
218
|
self.webViewController = WKWebViewController.init()
|
|
204
219
|
self.webViewController?.setHeaders(headers: headers)
|
|
@@ -241,6 +256,7 @@ public class InAppBrowserPlugin: CAPPlugin {
|
|
|
241
256
|
self.navigationWebViewController?.modalPresentationStyle = .fullScreen
|
|
242
257
|
if toolbarType == "blank" {
|
|
243
258
|
self.navigationWebViewController?.navigationBar.isHidden = true
|
|
259
|
+
self.webViewController?.blankNavigationTab = true
|
|
244
260
|
}
|
|
245
261
|
if showReloadButton {
|
|
246
262
|
let toolbarItems = self.getToolbarItems(toolbarType: toolbarType)
|
|
@@ -289,8 +305,10 @@ public class InAppBrowserPlugin: CAPPlugin {
|
|
|
289
305
|
call.reject("Cannot get script to execute")
|
|
290
306
|
return
|
|
291
307
|
}
|
|
292
|
-
|
|
293
|
-
|
|
308
|
+
DispatchQueue.main.async {
|
|
309
|
+
self.webViewController?.executeScript(script: script)
|
|
310
|
+
call.resolve()
|
|
311
|
+
}
|
|
294
312
|
}
|
|
295
313
|
|
|
296
314
|
@objc func postMessage(_ call: CAPPluginCall) {
|
|
@@ -302,7 +320,9 @@ public class InAppBrowserPlugin: CAPPlugin {
|
|
|
302
320
|
}
|
|
303
321
|
print("Event data: \(eventData)")
|
|
304
322
|
|
|
305
|
-
|
|
323
|
+
DispatchQueue.main.async {
|
|
324
|
+
self.webViewController?.postMessageToJS(message: eventData)
|
|
325
|
+
}
|
|
306
326
|
call.resolve()
|
|
307
327
|
}
|
|
308
328
|
|
|
@@ -75,6 +75,16 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
75
75
|
self.setPreventDeeplink(preventDeeplink: preventDeeplink)
|
|
76
76
|
self.initWebview(isInspectable: isInspectable)
|
|
77
77
|
}
|
|
78
|
+
|
|
79
|
+
public init(url: URL, headers: [String: String], isInspectable: Bool, credentials: WKWebViewCredentials? = nil, preventDeeplink: Bool, blankNavigationTab: Bool) {
|
|
80
|
+
super.init(nibName: nil, bundle: nil)
|
|
81
|
+
self.blankNavigationTab = blankNavigationTab
|
|
82
|
+
self.source = .remote(url)
|
|
83
|
+
self.credentials = credentials
|
|
84
|
+
self.setHeaders(headers: headers)
|
|
85
|
+
self.setPreventDeeplink(preventDeeplink: preventDeeplink)
|
|
86
|
+
self.initWebview(isInspectable: isInspectable)
|
|
87
|
+
}
|
|
78
88
|
|
|
79
89
|
open var hasDynamicTitle = false
|
|
80
90
|
open var source: WKWebSource?
|
|
@@ -101,6 +111,7 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
101
111
|
open var ignoreUntrustedSSLError = false
|
|
102
112
|
var viewWasPresented = false
|
|
103
113
|
var preventDeeplink: Bool = false
|
|
114
|
+
var blankNavigationTab: Bool = false;
|
|
104
115
|
|
|
105
116
|
internal var preShowSemaphore: DispatchSemaphore?
|
|
106
117
|
internal var preShowError: String?
|
|
@@ -239,7 +250,9 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
239
250
|
if let jsonData = try? JSONSerialization.data(withJSONObject: message, options: []),
|
|
240
251
|
let jsonString = String(data: jsonData, encoding: .utf8) {
|
|
241
252
|
let script = "window.dispatchEvent(new CustomEvent('messageFromNative', { detail: \(jsonString) }));"
|
|
242
|
-
|
|
253
|
+
DispatchQueue.main.async {
|
|
254
|
+
self.webView?.evaluateJavaScript(script, completionHandler: nil)
|
|
255
|
+
}
|
|
243
256
|
}
|
|
244
257
|
}
|
|
245
258
|
|
|
@@ -267,6 +280,8 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
267
280
|
}
|
|
268
281
|
print("[InAppBrowser - preShowScriptError]: Error!!!!")
|
|
269
282
|
semaphore.signal()
|
|
283
|
+
} else if message.name == "close" {
|
|
284
|
+
closeView()
|
|
270
285
|
}
|
|
271
286
|
}
|
|
272
287
|
|
|
@@ -278,6 +293,9 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
278
293
|
if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.messageHandler) {
|
|
279
294
|
window.webkit.messageHandlers.messageHandler.postMessage(message);
|
|
280
295
|
}
|
|
296
|
+
},
|
|
297
|
+
close: function() {
|
|
298
|
+
window.webkit.messageHandlers.close.postMessage(null);
|
|
281
299
|
}
|
|
282
300
|
};
|
|
283
301
|
}
|
|
@@ -288,7 +306,6 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
288
306
|
}
|
|
289
307
|
|
|
290
308
|
open func initWebview(isInspectable: Bool = true) {
|
|
291
|
-
|
|
292
309
|
self.view.backgroundColor = UIColor.white
|
|
293
310
|
|
|
294
311
|
self.extendedLayoutIncludesOpaqueBars = true
|
|
@@ -299,8 +316,9 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
299
316
|
userContentController.add(self, name: "messageHandler")
|
|
300
317
|
userContentController.add(self, name: "preShowScriptError")
|
|
301
318
|
userContentController.add(self, name: "preShowScriptSuccess")
|
|
302
|
-
|
|
319
|
+
userContentController.add(self, name: "close")
|
|
303
320
|
webConfiguration.allowsInlineMediaPlayback = true
|
|
321
|
+
webConfiguration.userContentController = userContentController
|
|
304
322
|
let webView = WKWebView(frame: .zero, configuration: webConfiguration)
|
|
305
323
|
|
|
306
324
|
if webView.responds(to: Selector(("setInspectable:"))) {
|
|
@@ -308,6 +326,20 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
308
326
|
webView.perform(Selector(("setInspectable:")), with: isInspectable)
|
|
309
327
|
}
|
|
310
328
|
|
|
329
|
+
if (self.blankNavigationTab) {
|
|
330
|
+
// First add the webView to view hierarchy
|
|
331
|
+
self.view.addSubview(webView)
|
|
332
|
+
|
|
333
|
+
// Then set up constraints
|
|
334
|
+
webView.translatesAutoresizingMaskIntoConstraints = false
|
|
335
|
+
NSLayoutConstraint.activate([
|
|
336
|
+
webView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor),
|
|
337
|
+
webView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
|
|
338
|
+
webView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
|
|
339
|
+
webView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor)
|
|
340
|
+
])
|
|
341
|
+
}
|
|
342
|
+
|
|
311
343
|
webView.uiDelegate = self
|
|
312
344
|
webView.navigationDelegate = self
|
|
313
345
|
|
|
@@ -319,9 +351,10 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
319
351
|
webView.addObserver(self, forKeyPath: titleKeyPath, options: .new, context: nil)
|
|
320
352
|
}
|
|
321
353
|
webView.addObserver(self, forKeyPath: #keyPath(WKWebView.url), options: .new, context: nil)
|
|
322
|
-
// NotificationCenter.default.addObserver(self, selector: #selector(restateViewHeight), name: UIDevice.orientationDidChangeNotification, object: nil)
|
|
323
354
|
|
|
324
|
-
self.
|
|
355
|
+
if (!self.blankNavigationTab) {
|
|
356
|
+
self.view = webView
|
|
357
|
+
}
|
|
325
358
|
self.webView = webView
|
|
326
359
|
|
|
327
360
|
self.webView?.customUserAgent = self.customUserAgent ?? self.userAgent ?? self.originalUserAgent
|
|
@@ -796,7 +829,6 @@ fileprivate extension WKWebViewController {
|
|
|
796
829
|
self.present(alert, animated: true, completion: nil)
|
|
797
830
|
} else {
|
|
798
831
|
let activityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil)
|
|
799
|
-
#imageLiteral(resourceName: "simulator_screenshot_B8B44B8D-EB30-425C-9BF4-1F37697A8459.png")
|
|
800
832
|
activityViewController.setValue(self.shareSubject ?? self.title, forKey: "subject")
|
|
801
833
|
activityViewController.popoverPresentationController?.barButtonItem = (sender as! UIBarButtonItem)
|
|
802
834
|
self.present(activityViewController, animated: true, completion: nil)
|
|
@@ -839,7 +871,16 @@ fileprivate extension WKWebViewController {
|
|
|
839
871
|
|
|
840
872
|
// MARK: - WKUIDelegate
|
|
841
873
|
extension WKWebViewController: WKUIDelegate {
|
|
842
|
-
|
|
874
|
+
public func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) {
|
|
875
|
+
// Ensure UI updates are on the main thread
|
|
876
|
+
DispatchQueue.main.async {
|
|
877
|
+
let alertController = UIAlertController(title: nil, message: message, preferredStyle: .alert)
|
|
878
|
+
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: { _ in
|
|
879
|
+
completionHandler()
|
|
880
|
+
}))
|
|
881
|
+
self.present(alertController, animated: true, completion: nil)
|
|
882
|
+
}
|
|
883
|
+
}
|
|
843
884
|
}
|
|
844
885
|
|
|
845
886
|
// MARK: - WKNavigationDelegate
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#import <UIKit/UIKit.h>
|
|
2
|
-
|
|
3
|
-
//! Project version number for Plugin.
|
|
4
|
-
FOUNDATION_EXPORT double PluginVersionNumber;
|
|
5
|
-
|
|
6
|
-
//! Project version string for Plugin.
|
|
7
|
-
FOUNDATION_EXPORT const unsigned char PluginVersionString[];
|
|
8
|
-
|
|
9
|
-
// In this header, you should import all the public headers of your framework using statements like #import <Plugin/PublicHeader.h>
|
|
10
|
-
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
#import <Foundation/Foundation.h>
|
|
2
|
-
#import <Capacitor/Capacitor.h>
|
|
3
|
-
|
|
4
|
-
// Define the plugin using the CAP_PLUGIN Macro, and
|
|
5
|
-
// each method the plugin supports using the CAP_PLUGIN_METHOD macro.
|
|
6
|
-
CAP_PLUGIN(InAppBrowserPlugin, "InAppBrowser",
|
|
7
|
-
CAP_PLUGIN_METHOD(openWebView, CAPPluginReturnPromise);
|
|
8
|
-
CAP_PLUGIN_METHOD(clearCookies, CAPPluginReturnPromise);
|
|
9
|
-
CAP_PLUGIN_METHOD(getCookies, CAPPluginReturnPromise);
|
|
10
|
-
CAP_PLUGIN_METHOD(clearAllCookies, CAPPluginReturnPromise);
|
|
11
|
-
CAP_PLUGIN_METHOD(clearCache, CAPPluginReturnPromise);
|
|
12
|
-
CAP_PLUGIN_METHOD(reload, CAPPluginReturnPromise);
|
|
13
|
-
CAP_PLUGIN_METHOD(open, CAPPluginReturnPromise);
|
|
14
|
-
CAP_PLUGIN_METHOD(setUrl, CAPPluginReturnPromise);
|
|
15
|
-
CAP_PLUGIN_METHOD(show, CAPPluginReturnPromise);
|
|
16
|
-
CAP_PLUGIN_METHOD(close, CAPPluginReturnPromise);
|
|
17
|
-
CAP_PLUGIN_METHOD(hide, CAPPluginReturnPromise);
|
|
18
|
-
CAP_PLUGIN_METHOD(executeScript, CAPPluginReturnPromise);
|
|
19
|
-
CAP_PLUGIN_METHOD(postMessage, CAPPluginReturnPromise);
|
|
20
|
-
CAP_PLUGIN_METHOD(insertCSS, CAPPluginReturnPromise);
|
|
21
|
-
)
|