Skip to main content

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:

npm install @ionic-enterprise/inappbrowser
npx cap sync

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:

NameTypeDescription
urlstringThe URL to load.
Optional targetstringThe target in which to load the URL, an optional parameter that defaults to _self.
Optional optionsstring | InAppBrowserOptionsOptions 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:

NameType
typestring
Optional eventInitDictEventInit

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:

NameType
typestring
Optional bubblesboolean
Optional cancelableboolean

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).


● 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 InAppBrowserStatusBarStyle '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 InAppBrowserStatusBarStyle preference
  • undo whitespace changes due to editor preferrences
  • GH-728 iOS: added InAppBrowserStatusBarStyle 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)

3.0.0 (Apr 12, 2018)

  • CB-13659 iOS Add hidespinner option
  • In file AppBrowser.java: New code within shouldOverrideUrlLoading() to check for whitelisting custom schemes via a new AllowedSchemes preference configuration item. Allows custom schemes like mycoolapp:// or wevotetwitterscheme://
  • InAppBrowser.java: New method isURLWhileListed to check for whitelisting of AllowedSchemes in a new preference configuration item. There is a new check in shouldOverrideUrlLoading, to allow whitelisted custom schemes like "mycoolapp://"
  • Add customisation of the navigation buttons for iOS
  • Fix navigation buttons on iOS