Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

cordova-plugin-ionic-webview

ionic-team67.7kApache-2.05.0.1

Ionic Web View Engine Plugin

cordova, wkwebview

readme

semantic-release Dependabot Status npm

Ionic Web View for Cordova

A Web View plugin for Cordova, focused on providing the highest performance experience for Ionic apps (but can be used with any Cordova app).

This plugin uses WKWebView on iOS and the latest evergreen webview on Android. Additionally, this plugin makes it easy to use HTML5 style routing that web developers expect for building single-page apps.

Note: This repo and its documentation are for cordova-plugin-ionic-webview @ 5.x, which uses the new features that may not work with all apps. See Requirements and Migrating to 5.x.

2.x documentation can be found here.

:book: Documentation: https://beta.ionicframework.com/docs/building/webview

:mega: Support/Questions? Please see our Support Page for general support questions. The issues on GitHub should be reserved for bug reports and feature requests.

:sparkling_heart: Want to contribute? Please see CONTRIBUTING.md.

Configuration

This plugin has several configuration options that can be set in config.xml.

Android and iOS Preferences

Preferences available for both iOS and Android

Hostname

<preference name="Hostname" value="app" />

Default value is localhost.

Example ionic://app on iOS, http://app on Android.

If you change it, you'll need to add a new allow-navigation entry in the config.xml for the configured url (i.e <allow-navigation href="http://app/*"/> if Hostname is set to app). This is only needed for the Android url when using http://, https:// or a custom scheme. All ionic:// urls are whitelisted by the plugin.

Android Preferences

Preferences only available Android platform

Scheme

<preference name="Scheme" value="https" />

Default value is http

Configures the Scheme the app uses to load the content.

ResolveServiceWorkerRequests

<preference name="ResolveServiceWorkerRequests" value="true" />

Default value is false

Enable to resolve requests made by Service Workers through the local server.

MixedContentMode

<preference name="MixedContentMode" value="2" />

Configures the WebView's behavior when an origin attempts to load a resource from a different origin.

Default value is 0 (MIXED_CONTENT_ALWAYS_ALLOW), which allows loading resources from other origins.

Other possible values are 1 (MIXED_CONTENT_NEVER_ALLOW) and 2 (MIXED_CONTENT_COMPATIBILITY_MODE)

Android documentation

iOS Preferences

Preferences only available for iOS platform

iosScheme

<preference name="iosScheme" value="httpsionic" />

Default value is ionic

Configures the Scheme the app uses to load the content.

Values like http, https or file are not valid and will use default value instead.

If you change it, you'll need to add a new allow-navigation entry in the config.xml for the configured scheme (i.e <allow-navigation href="httpsionic://*"/> if iosScheme is set to httpsionic).

WKSuspendInBackground

<preference name="WKSuspendInBackground" value="false" />

Default value is true (suspend).

Set to false to stop WKWebView suspending in background too eagerly.

KeyboardAppearanceDark

<preference name="KeyboardAppearanceDark" value="false" />

Whether to use a dark styled keyboard on iOS

ScrollEnabled

<preference name="ScrollEnabled" value="true" />

Ionic apps work better if the WKWebView is not scrollable, so the scroll is disabled by default, but can be enabled with this preference. This only affects the main ScrollView of the WKWebView, so only affects the body, not other scrollable components.

Plugin Requirements

  • Cordova CLI: 7.1.0+
  • iOS: iOS 11+ and cordova-ios 4+
  • Android: Android 5+ and cordova-android 6.4+

Migrating to 5.x

  1. Remove and re-add the Web View plugin:

     cordova plugin rm cordova-plugin-ionic-webview
     cordova plugin add cordova-plugin-ionic-webview@latest
  2. If using cordova-android < 9, make sure you have <preference name="android-minSdkVersion" value="21" /> in the config.xml as this version of the plugin only supports Android 5+ (SDK 21+). If using cordova-android >= 9 is not neccessary as cordova-android 9 only supports Android 5.1+ (SDK 22+)

  3. Since version 2, apps are served from HTTP on Android by default.

    • The default origin for requests from the Android WebView is http://localhost. If Hostname and Scheme preferences are set, then origin will be schemeValue://HostnameValue.
  4. Since version 3, apps are served from ionic:// scheme on iOS by default.

    • The default origin for requests from the iOS WebView is ionic://localhost. If Hostname and iosScheme preferences are set, then origin will be iosSchemeValue://HostnameValue.
  5. The WebView is not able to display images, videos or other files from file or content protocols or if it doesn't have protocol at all. For those cases use window.Ionic.WebView.convertFileSrc() to get the proper url.

  6. Replace any usages of window.Ionic.normalizeURL() and window.wkRewriteURL() with window.Ionic.WebView.convertFileSrc().

    • For Ionic Angular projects, there is an Ionic Native wrapper:

        npm install @ionic-native/ionic-webview@latest

changelog

5.0.0 (2020-05-27)

Features

  • android: remove RequiresApi annotation and drop support for API 19 (#540) (17d2ada)
  • ios: remove normalizeURL function (#576) (d5bdbaa)
  • ios: remove wkRewriteURL function (#577) (02c18ea)

BREAKING CHANGES

  • ios: wkRewriteURL was deprecated and has been removed, use window.Ionic.WebView.convertFileSrc instead
  • ios: normalizeURL was deprecated and has been removed, use window.Ionic.WebView.convertFileSrc instead
  • android: Drop Android 4.4 support (SDK API level 19). Min required is 21.

4.2.1 (2020-04-28)

Bug Fixes

4.2.0 (2020-04-14)

Bug Fixes

  • ionassethandler.m: fix startPath is getting null (#463) (0bf16f1)
  • ios: avoid app scrolling to top on keyboard hide (#533) (7974eb4)
  • ios: Replace deprecated APIs (#539) (27b9021)

Features

  • android: proxy service worker requests through local server (#452) (c672175)
  • ios: implement custom userAgent handling (#537) (8587114)

4.1.3 (2019-10-30)

Bug Fixes

  • android: return proper mimeType for .mjs files (#455) (173a313)
  • ios: mitigate media memory usage (#459) (cbd526d)
  • ios: remove itms-services private scheme (#464) (d7d2600)

4.1.2 (2019-09-25)

Bug Fixes

  • android: allow schemes that start by https (#437) (fab9d1f)
  • Android: return proper mimeType for wasm files (0eb8a37)
  • ios: make programmatically focus work on iOS 13 (#438) (7a514b0), closes #435

4.1.1 (2019-06-26)

Bug Fixes

  • ios: show error message when app fails to load (#382) (cb1f026)

4.1.0 (2019-06-10)

Features

  • ios: Add WKSuspendInBackground preference (#356) (3613602)

4.0.1 (2019-03-26)

Bug Fixes

4.0.0 (2019-02-18)

Features

  • ios: Make iOS app Scheme configurable with a preference (#307) (d52d37e), closes #282
  • ios: Remove WKSuspendInBackground preference (#309) (73b6659), closes #286

BREAKING CHANGES

  • ios: Remove the WKSuspendInBackground preference, so app relying on that prefere will not behave as expected

3.1.2 (2019-02-04)

Bug Fixes

3.1.1 (2019-01-18)

Bug Fixes

3.1.0 (2019-01-17)

Bug Fixes

  • ios: Fix video playback of files with uppercase extension (#264) (2c4b225), closes #260
  • Set engines to require Cordova CLI 7.1.0 or newer (#276) (40f42e1), closes #263
  • Use a single scheme for all files (#270) (3d1bcdd), closes #258

Features

3.0.0 (2019-01-03)

Bug Fixes

Features

  • Allows configuration of Mixed Content Mode (#240) (486d412), closes #231
  • Android: Implement ionic-file and ionic-content urls (#242) (8ef0c30), closes #204 #183
  • iOS: Remove GCDWebServer (#244) (0dee0cf)
  • WebViewLocalServer.java: return 404 error code when a local file is not found (#217) (f7a551e), closes #216

BREAKING CHANGES

  • iOS: Sets deployment-target to 11, so will only work on iOS 11+

  • Address changes

  • changes the default from 1 (never) to 0 (always)
  • WebViewLocalServer.java: Until now, the Android part of the plugin was returning a 200 http code even though the requested file didn't exist. This behavior was inconsistent with the historical behavior of the iOS webView. This change makes them both work in the same manner but introduces a breaking change for the current Android users that are expecting a 200 http code no matter what and are testing the not found error just by checking if the body is null.

2.3.1 (2018-12-06)

Bug Fixes

  • Handle convertFileSrc when using ionic:// scheme (#236) (89ce899)

2.3.0 (2018-12-05)

Features

  • ios: Add URLSchemeHandler for iOS 11+ (#221) (4a973f4)

2.2.5 (2018-11-20)

Bug Fixes

  • Add option for Dark keyboard appearance (#44) (6c0fe56)

2.2.4 (2018-11-20)

Bug Fixes

  • fix keyboard displacement bug in iOS 12 WKWebView (#201) (a670568)

2.2.3 (2018-11-09)

Bug Fixes

  • Remove main and fix description (d52db66)

2.2.2 (2018-11-09)

Bug Fixes

  • Add more server checks before loading urls or reloading (#211) (60eff2f)

2.2.1 (2018-11-07)

Bug Fixes

  • Show error page if server is not running (#207) (6a2e07e)

2.2.0 (2018-10-04)

  • Fix issue where two apps running on the same port could conflict with each other (#169 & #186)
  • Add kitkat support (API 19) (#144) @leo6104
  • Fix issue where local server was being used if launch URL is external (#169)

2.1.4 (2018-09-13)

  • Allow Ionic Deploy DisableDeploy preference to disable loading of deploy updates (#172)

2.1.3 (2018-09-06)

  • Make server path relative (#164)

2.1.2 (2018-09-05)

  • Return 404 response when file doesn't exist (#162)
  • Load local assets if the app is a freshly installed binary (#155)
  • Reset stored server path on new binary (#161)

2.1.1 (2018-09-04)

  • Allow range requests for local files (#154)

2.1.0 (2018-08-23)

  • Add support for cordova-android 6 (#150)

2.0.3 (2018-08-14)

  • Fix nil reference by setting up the server URL before routes are set up. (#135) @matejkramny
  • Resolve issue when app is launched in background. (#124) @ghenry22

2.0.2 (2018-07-30)

  • Immediately load new server base path upon setting it. (#132)

2.0.1 (2018-07-25)

  • Avoid "not modified" response on iOS by always overriding last modified date. (#127)

2.0.0 (2018-07-23)

  • BREAKING: HTTP server now runs for iOS and Android, instead of just iOS. The server is configured the same for both platforms.
  • BREAKING: HTTP server now loads the app from a base href of /. The app URL behaves like http://localhost:8080/index.html instead of http://localhost:8080/Users/.../index.html.
  • BREAKING: HTTP server is configured to run in HTML5 routing mode (push state) by default.
  • BREAKING: File access through the Web View must be served by the HTTP server to avoid security errors in the Web View. Loading files via file:// is not allowed by the Web View. The HTTP server will serve files via the _file_ prefix, e.g. http://localhost:8080/_file_/Users/.../file.png.
  • window.Ionic.normalizeURL() has been deprecated. Use window.Ionic.WebView.convertFileSrc().
  • iOS update HTTP server to latest upstream version (GCDwebserve 3.4.2)
  • iOS update HTTP server to restart sockets with error state when resuming from background
  • iOS enable HTTP server to continue running in background if the webview is running.
  • iOS enable Webview to continue running in background. Requires background mode capability enabled in xcode + valid use case as per app store requirements. If your app is not performing valid background tasks it will still be suspended by the OS as usual. As long as valid background tasks are running the webview will continue to function as expected.
  • iOS add config.xml options:
    • WKSuspendInBackground - defaults to true, if set to false then the webview and HTTP server will continue to run when the app is in the background or screen is locked
    • WKPort - defaults to 8080, define the port that the HTTP server will listen on
    • WKBind - defaults to localhost, if set to 127.0.0.1 then this IP will be used instead of the localhost hostname for the HTTP server

See Github releases for earlier changes.