InAppBrowser
EOL Notice
InAppBrowser will reach its end-of-life on July 1, 2024, and will no longer receive updates or support. Please see Support Policy for additional information.
The InAppBrowser plugin provides the ability to launch a web browser within the app.
Installation
If you have not already setup Ionic Enterprise in your app, follow the one-time setup steps.
Next, install the plugin:
- Capacitor
- Cordova
npm install @ionic-enterprise/inappbrowser
npx cap sync
ionic cordova plugin add @ionic-enterprise/inappbrowser
Index
Classes
Interfaces
Type aliases
Classes
InAppBrowser
InAppBrowser:
name: In App Browser
description: Launches in app Browser
usage:
import { InAppBrowser } from '@ionic-enterprise/inappbrowser/ngx';
constructor(private iab: InAppBrowser) { }
...
const browser = this.iab.create('https://ionicframework.com/');
browser.executeScript(...);
browser.insertCSS(...);
browser.on('loadstop').subscribe(event => {
browser.insertCSS({ code: "body{color: red;" });
});
browser.close();
classes: InAppBrowserObject
interfaces: InAppBrowserEvent InAppBrowserOptions
create
▸ create(url: string
, target?: string
, options?: string
| InAppBrowserOptions): InAppBrowserObject
Opens a URL in a new InAppBrowser instance, the current browser instance, or the system browser.
Parameters:
Name | Type | Description |
---|---|---|
url | string | The URL to load. |
Optional target | string | The target in which to load the URL, an optional parameter that defaults to _self. |
Optional options | string | InAppBrowserOptions | Options for the InAppBrowser. Optional, defaulting to: location=yes. The options string must not contain any blank space, and each feature's name/value pairs must be separated by a comma. Feature names are case insensitive. |
Returns: InAppBrowserObject
Interfaces
InAppBrowserEvent
InAppBrowserEvent:
AT_TARGET
● AT_TARGET: number
BUBBLING_PHASE
● BUBBLING_PHASE: number
CAPTURING_PHASE
● CAPTURING_PHASE: number
Event
● Event: object
Type declaration
constructor : function
⊕ new __type(type: string
, eventInitDict?: EventInit
): Event
Parameters:
Name | Type |
---|---|
type | string |
Optional eventInitDict | EventInit |
Returns: Event
AT_TARGET: number
BUBBLING_PHASE: number
CAPTURING_PHASE: number
NONE: number
prototype: Event
NONE
● NONE: number
bubbles
● bubbles: boolean
Returns true or false depending on how event was initialized. True if event goes through its target's ancestors in reverse tree order, and false otherwise.
cancelBubble
● cancelBubble: boolean
cancelable
● cancelable: boolean
code
● code: number
the error code, only in the case of loaderror.
composed
● composed: boolean
Returns true or false depending on how event was initialized. True if event invokes listeners past a ShadowRoot node that is the root of its target, and false otherwise.
currentTarget
● currentTarget: EventTarget
| null
Returns the object whose event listener's callback is currently being invoked.
defaultPrevented
● defaultPrevented: boolean
eventPhase
● eventPhase: number
isTrusted
● isTrusted: boolean
Returns true if event was dispatched by the user agent, and false otherwise.
message
● message: string
the error message, only in the case of loaderror.
returnValue
● returnValue: boolean
srcElement
● srcElement: Element
| null
deprecated:
target
● target: EventTarget
| null
Returns the object to which event is dispatched (its target).
timeStamp
● timeStamp: number
Returns the event's timestamp as the number of milliseconds measured relative to the time origin.
type
● type: InAppBrowserEventType
the event name
url
● url: string
the URL that was loaded.
composedPath
▸ composedPath(): EventTarget
[]
Returns: EventTarget
[]
initEvent
▸ initEvent(type: string
, bubbles?: boolean
, cancelable?: boolean
): void
Parameters:
Name | Type |
---|---|
type | string |
Optional bubbles | boolean |
Optional cancelable | boolean |
Returns: void
preventDefault
▸ preventDefault(): void
Returns: void
stopImmediatePropagation
▸ stopImmediatePropagation(): void
Invoking this method prevents event from reaching any registered event listeners after the current one finishes running and, when dispatched in a tree, also prevents event from reaching any other objects.
Returns: void
stopPropagation
▸ stopPropagation(): void
When dispatched in a tree, invoking this method prevents event from reaching any objects other than the current object.
Returns: void
InAppBrowserOptions
InAppBrowserOptions:
<Optional>
allowInlineMediaPlayback
● allowInlineMediaPlayback: "yes" | "no"
(iOS Only) Set to yes or no to allow in-line HTML5 media playback, displaying within the browser window rather than a device-specific playback interface. The HTML's video element must also include the webkit-playsinline attribute (defaults to no)
<Optional>
beforeload
● beforeload: "yes" | "get" | "post"
set to enable the beforeload event to modify which pages are actually loaded in the browser. Accepted values are get to intercept only GET requests, post to intercept on POST requests or yes to intercept both GET & POST requests. Note that POST requests are not currently supported and will be ignored (if you set beforeload=post it will raise an error).
<Optional>
clearcache
● clearcache: "yes"
Set to yes to have the browser's cookie cache cleared before the new window is opened.
<Optional>
cleardata
● cleardata: "yes"
set to yes to have the browser's entire local storage cleared (cookies, HTML5 local storage, IndexedDB, etc.) before the new window is opened
<Optional>
clearsessioncache
● clearsessioncache: "yes"
Set to yes to have the session cookie cache cleared before the new window is opened. For WKWebView, requires iOS 11+ on target device.
<Optional>
closebuttoncaption
● closebuttoncaption: string
(Android) Set to a string to use as the close button's caption instead of a X. Note that you need to localize this value yourself. (iOS) Set to a string to use as the Done button's caption. Note that you need to localize this value yourself.
<Optional>
closebuttoncolor
● closebuttoncolor: string
(Android) Set to a valid hex color string, for example: #00ff00, and it will change the close button color from default, regardless of being a text or default X. Only has effect if user has location set to yes. (iOS) Set as a valid hex color string, for example: #00ff00, to change from the default Done button's color. Only applicable if toolbar is not disabled.
<Optional>
disallowoverscroll
● disallowoverscroll: "yes" | "no"
(iOS Only) Set to yes or no (default is no). Turns on/off the UIWebViewBounce property.
<Optional>
enableViewportScale
● enableViewportScale: "yes" | "no"
(iOS Only) Set to yes or no to prevent viewport scaling through a meta tag (defaults to no).
<Optional>
footer
● footer: "yes" | "no"
(Android Only) Set to yes to show a close button in the footer similar to the iOS Done button. The close button will appear the same as for the header hence use closebuttoncaption and closebuttoncolor to set its properties
<Optional>
footercolor
● footercolor: string
(Android Only) Set to a valid hex color string, for example #00ff00 or #CC00ff00 (#aarrggbb), and it will change the footer color from default. Only has effect if user has footer set to yes
<Optional>
fullscreen
● fullscreen: "yes"
(Windows only) Set to yes to create the browser control without a border around it. Please note that if location=no is also specified, there will be no control presented to user to close IAB window.
<Optional>
hardwareback
● hardwareback: "yes" | "no"
(Android & Windows Only) Set to yes to use the hardware back button to navigate backwards through the InAppBrowser's history. If there is no previous page, the InAppBrowser will close. The default value is yes, so you must set it to no if you want the back button to simply close the InAppBrowser.
<Optional>
hidden
● hidden: "yes" | "no"
Set to yes to create the browser and load the page, but not show it. The loadstop event fires when loading is complete. Omit or set to no (default) to have the browser open and load normally.
<Optional>
hidenavigationbuttons
● hidenavigationbuttons: "yes" | "no"
(Android) Set to yes to hide the navigation buttons on the location toolbar, only has effect if user has location set to yes. The default value is no. (iOS) Set to yes or no to turn the toolbar navigation buttons on or off (defaults to no). Only applicable if toolbar is not disabled.
<Optional>
hidespinner
● hidespinner: "yes" | "no"
(iOS Only) Set to yes or no to change the visibility of the loading indicator (defaults to no).
<Optional>
hideurlbar
● hideurlbar: "yes" | "no"
(Android) Set to yes to hide the url bar on the location toolbar, only has effect if user has location set to yes. The default value is no.
<Optional>
keyboardDisplayRequiresUserAction
● keyboardDisplayRequiresUserAction: "yes" | "no"
(iOS Only) Set to yes or no to open the keyboard when form elements receive focus via JavaScript's focus() call (defaults to yes).
<Optional>
lefttoright
● lefttoright: "yes" | "no"
(Android) Set to yes to swap positions of the navigation buttons and the close button. Specifically, navigation buttons go to the left and close button to the right. (iOS) Set to yes to swap positions of the navigation buttons and the close button. Specifically, close button goes to the right and navigation buttons to the left.
<Optional>
location
● location: "yes" | "no"
Set to yes or no to turn the InAppBrowser's location bar on or off.
<Optional>
mediaPlaybackRequiresUserAction
● mediaPlaybackRequiresUserAction: "yes" | "no"
Set to yes to prevent HTML5 audio or video from autoplaying (defaults to no).
<Optional>
navigationbuttoncolor
● navigationbuttoncolor: string
(Android) Set to a valid hex color string, for example: #00ff00, and it will change the color of both navigation buttons from default. Only has effect if user has location set to yes and not hidenavigationbuttons set to yes. (iOS) Set as a valid hex color string, for example: #00ff00, to change from the default color. Only applicable if navigation buttons are visible.
<Optional>
presentationstyle
● presentationstyle: "pagesheet" | "formsheet" | "fullscreen"
(iOS Only) Set to pagesheet, formsheet or fullscreen to set the presentation style (defaults to fullscreen).
<Optional>
shouldPauseOnSuspend
● shouldPauseOnSuspend: "yes" | "no"
(Android Only) Set to yes to make InAppBrowser WebView to pause/resume with the app to stop background audio (this may be required to avoid Google Play issues)
<Optional>
suppressesIncrementalRendering
● suppressesIncrementalRendering: "yes" | "no"
(iOS Only) Set to yes or no to wait until all new view content is received before being rendered (defaults to no).
<Optional>
toolbar
● toolbar: "yes" | "no"
(iOS Only) Set to yes or no to turn the toolbar on or off for the InAppBrowser (defaults to yes)
<Optional>
toolbarcolor
● toolbarcolor: string
(Android) Set to a valid hex color string, for example: #00ff00, and it will change the color the toolbar from default. Only has effect if user has location set to yes. (iOS) Set as a valid hex color string, for example: #00ff00, to change from the default color of the toolbar. Only applicable if toolbar is not disabled.
<Optional>
toolbarposition
● toolbarposition: "top" | "bottom"
(iOS Only) Set to top or bottom (default is bottom). Causes the toolbar to be at the top or bottom of the window.
<Optional>
toolbartranslucent
● toolbartranslucent: "yes" | "no"
(iOS Only) Set to yes or no to make the toolbar translucent(semi-transparent) (defaults to yes). Only applicable if toolbar is not disabled.
<Optional>
transitionstyle
● transitionstyle: "fliphorizontal" | "crossdissolve" | "coververtical"
(iOS Only) Set to fliphorizontal, crossdissolve or coververtical to set the transition style (defaults to coververtical).
<Optional>
useWideViewPort
● useWideViewPort: "yes" | "no"
(Android Only) Sets whether the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport. When the value of the setting is no, the layout width is always set to the width of the WebView control in device-independent (CSS) pixels. When the value is yes and the page contains the viewport meta tag, the value of the width specified in the tag is used. If the page does not contain the tag or does not provide a width, then a wide viewport will be used. (defaults to yes).
<Optional>
zoom
● zoom: "yes" | "no"
(Android Only) Set to yes to show Android browser's zoom controls, set to no to hide them. Default value is yes.
Type aliases
InAppBrowserEventType
Ƭ InAppBrowserEventType: "loadstart" | "loadstop" | "loaderror" | "exit" | "beforeload" | "message"
Release Notes
5.0.0 (Feb 10, 2021)
- GH-828 feat(ios): add
InAppBrowser
StatusBarStyle 'darkcontent' configuration option - GH-823 chore: bump engines requirements
- GH-824 breaking: cleanup code for old Android versions
- GH-825 (ios): rename CDVWKProcessPoolFactory
- GH-826 ci: add node-14.x to workflow
- GH-821 breaking(android): replace magic numbers with Android.os.Build constants
- GH-717 ci(ios): remove wkwebview plugin
4.1.0 (Nov 17, 2020)
- GH-792 fix(android): Add mitigation strategy for CVE-2020-6506
- GH-817 Updated typings
- GH-803 fix(android): allow compilation in old
cordova-android
versions - GH-688 (ios): allow to set "preferredContentMode"
- GH-768 ci(travis): update osx xcode image
- add documentation for
InAppBrowser
StatusBarStyle preference - undo whitespace changes due to editor preferrences
- GH-728 iOS: added
InAppBrowser
StatusBarStyle preference - GH-767 ci(travis): updates Android API level
- (ios): Fix incorrect view height from the second open time
- GH-748 chore: adds package-lock file
- GH-746 chore(npm): use short notation in
package.json
- GH-747 refactor(eslint): use cordova-eslint /w fix
- GH-737 fix(ios): exit event not fired on swipe down
4.0.0 (Jun 09, 2020)
- GH-715 (ios): fix regression in 2706f34
- GH-656 (ios) Remove fake status bar with hardcoded height to fix issues in iOS devices with a notch
- GH-693 fix(ios): Allow loading local html files
- GH-293 Android: SSL errors handling in Android
- GH-672 fix(ios): prevent statusbar rotation after closing
InAppBrowser
- GH-669 Allow App using
InAppBrowser
to be hosted in a cross-origin iframe - GH-600 (all platforms): remove "window.open" overwrite
- GH-515 Fix incorrect TypeScript typings
- GH-654 add check for openInSystem postNotification
- GH-442 fix(android): Reset lefttoright if not set
- GH-648 (android) Correcting the documentation regarding lefttoright opt…
- GH-634 (android) Added option to turn on/off fullscreen mode in Android
- GH-616 (android)
InAppBrowser
: java.lang.IllegalArgumentException - GH-635 breaking(ios): remove UIWebView
- GH-503 Defensive code to prevent NULL reference exceptions for async
- GH-524 Replace "beforeload" with BEFORELOAD
- GH-568 Update missing closed brace to the insert.CSS
- GH-401 Move createIframeBridge to injectDeferredObject
3.2.2 (Dec 13, 2019)
- fix: update types to make beforeload work
- chore: remove unused usewkwebview references
3.2.1 (Oct 01, 2019)
- fix(ios): make create work on iOS 13
3.2.0 (Sept 06, 2019)
- feat(ios): remove UIWebView code
3.1.0 (Jun 27, 2019)
- chore: fix repo and issue urls and license in package.json and plugin.xml (
8edfb9e
) - chore: unknown changes because of linebreak change in binary files (
e44ad91
) - build: add
.npmignore
to remove unneeded files from npm package (0ec4a11
) - build: add
.gitattributes
to force LF (instead of possible CRLF on Windows) (2751255
) - ci(travis): Update Travis CI configuration for new paramedic (#478) (
c2bb6c1
) - docs: remove outdated translations (
cc5ee00
) - fix(android): Fix beforeload for Android <= 7 (#427) (
94fec84
) - ci(travis) Fix failing CI tests (#460) (
a162bd9
) - test: Fix test spec.5 to close inappbrowser after loadstop event (#440) (
5f1afbd
,af44235
) - fix(android): Prevent malformed callbackId from reaching app cordova view (#436) (
6861084
,c95dbcb
) - feat: CB-13969: Allow close button and navigation buttons positions to be swapped (#262) (
d01bd25
,f861655
,9c7c2f3
,3c0a42e
,5359f6c
,df84dda
,2bcec40
,fc0c560
,5ead1e6
,c7931fa
,e2adf1b
,4adf4c7
,cbe3a42
,74ccef1
,ec6af56
,b06ad8e
,313e0ae
,05e37a1
,0c6189e
,d940b59
,f3d7f72
) - docs: Add headline to window.open documentation (#406) (
92243cd
) - fix(ios): Fix iframes in iOS/WKWebView which were broken by #418 (#425) (
388e3f6
) - chore(github): Add or update GitHub pull request and issue template (
ae329bc
) - fix(ios): Handle non-default target attribute values (e.g. target=on links in WKWebView implementation on iOS (#418) (
9f4b729
) - fix(types): remove unused replace parameter (#410) (
6db2f2d
) - documentation: Example documentation - Fix callBack function name (#383) (
a890e60
,2500b08
) - fix: Fix beforeload to work with POST requests (#367) (
632a395
) - feat: (iOS & Android) Add postMessage API support (#362) (
c54d100
) - fix(ios): Fixes loadAfterBeforeload on iOS. (#350) (
0fd43ae
) - fix(ios): Fix crashes when using WKWebView implementation on iOS 9. (#337) (
3b82c16
) - fix(ios): Fix iOS CDVWKInAppBrowser evaluateJavascript method randomly gets blocked on ios 12 (#341) (
978b147
) - docs: remove unwanted information in README table (#308) (
3eadde6
) - fix(ios): This lets the default window layering do it's thing. (#336) (
c24bb46
,27fe8ec
) - feat(ios): CB-7179 (iOS): Add optional WKWebView support for iOS (#271) (
10a0669
,3927b8f
,8248215
,61014dd
,c41f5b5
,19c6dfe
,7f5fa2a
,5d2df21
,86cc778
,cbfa195
,52e3534
,8165232
,e2210bd
,dc7fa34
,b48e02f
,27e6c67
) - docs: remove JIRA link (
d9cafcd
) - chore(types): CB-12941: update typings (#267) (
a0c267f
) - feat: CB-14188: add beforeload event, catching navigation before it happens (#276) (
228703a
,eafaeda
) - ci(travis): reenable testing on all platforms (
0ed0bf5
) - ci(travis): also accept terms for android sdk
android-27
(f8ad528
) - fix(android): CB-10795: Exclude current app from external intent list (#154) (
a078337
) - fix(ios): CB-14234: Don't call handleOpenURL for system URLs (#278) (
cf58b04
) - fix(ios): CB-12875: (iOS) Pushes the inappbrowser window to a higher ui level than the existing apps window. (#284) (
dc5329d
) - ci: Quick CI fixes (#277) (
de86501
,07d9a99
,81f1437
,a464ea6
,e75fe14
,eb245ec
) - fix(ios): CB-12922 (ios): fix In-app browser does not cede control (#272) (
dac06aa
,9cc7f69
) - fix(android): CB-14061: (android) comply with RFC 3986 for custom URL scheme handling (#269) (
f57ede9
,26cf6e4
) - fix(android): CB-14048: (android) allowedSchemes check empty string fix (#268) (
57eda78
,33aff11
)
3.0.0 (Apr 12, 2018)
- CB-13659 iOS Add hidespinner option
- In file
AppBrowser.java
: New code withinshouldOverrideUrlLoading()
to check for whitelisting custom schemes via a newAllowedSchemes
preference configuration item. Allows custom schemes likemycoolapp://
orwevotetwitterscheme://
InAppBrowser.java
: New methodisURLWhileListed
to check for whitelisting ofAllowedSchemes
in a new preference configuration item. There is a new check inshouldOverrideUrlLoading
, to allow whitelisted custom schemes like "mycoolapp://"- Add customisation of the navigation buttons for iOS
- Fix navigation buttons on iOS