Skip to content
Felix Schauerte edited this page Apr 7, 2022 · 8 revisions

Welcome to the cordova-plugin-safariviewcontroller wiki!

If you liked this plugin, we invite you to check out its new (experimental) android side, powered by Chrome custom tabs. Please note that this part of the plugin is not stable, so API may change in the future

To use with Chrome custom tabs for android:

  1. In Android Studio: open the SDK manager, then go to the 'SDK Tools' tab, and check 'Android Support Repository' (You only need to do it once per machine, it's also available via CLI if you don't use Android Studio).

  2. Install the master version of the plugin cordova plugin add --save https://github.com/EddyVerbruggen/cordova-plugin-safariviewcontroller

Documentation

As a rule of thumb, The API is meant to be equal to the iOS version of the plugin as much as possible

isAvailable

isAvailable(callback) just like in the iOS version of the plugin.

Show

As in iOS it accepts an options object and a success and fail callbacks. show({options}, successCallback, failCallback)

Options:

  • url - String, required.
  • toolbarColor - String, default: light gray. Supported formats are: #RRGGBB #AARRGGBB or a named color (full list).
  • animated - Boolean, default: true.
  • transition - String, default: "slide" (it's also the only animation available at the moment) The browser window will slide in from the right.
  • showDefaultShareMenuItem (default false) - if set to true, will add a menu entry to share the current URL.

any other option will be ignored.

successCallback(data) may be called once when the tab is loaded and once when it is closed. an object with one property: event that describes what happened is supplied (equals to either 'loaded' or 'closed').

You can get better performance if you will call warmUp and mayLaunchUrl before the call to show (see below). but don't forget to read through the Best practices section

errorCallback(error) is called when someting went wrong.

connectToService

connectToService(successCallback, failCallback) - trying to connect to the Chrome's custom tabs service. you must call this method before calling any of the other methods listed below.

warmUp

warmUp(successCallback, failCallback) - call this method whenever there's a chance the user will open an external url.

mayLaunchUrl

mayLaunchUrl(url, success, fail) - for even better performance optimization, call this methods if there's more than a 50% chance the user will open a certain URL.