Giter Site home page Giter Site logo

cordova-plugin-webviewselector's Introduction

cordova-plugin-webviewselector

This plugin is designed to allow developers that are using Crosswalk with cordova-plugin-crosswalk-webview to be able to switch dynamically between Crosswalk webview and default system webview (on Android).

Why anyone would want that?

Crosswalk being not maintained anymore, the future is in the use of system's webview. But on older devices you may want to keep a well working older version of Chromium. You may also want to let your application's users to switch themselves between engines for some reasons, like if your heuristic to select the best engine automatically depending on their device is not perfect.

How is it working?

This plugin is only changing Cordova's webview setting dynamically before the creation of the webview.

Compatibility

Currently tested with:

  • Cordova Android Engine 4.1.1.
  • Cordova CLI 6.5.0.

TODO: test on more recent versions.

Prerequisites

You need to have cordova-plugin-crosswalk-webview installed in your project.

Installation

After having added the plugin to your project, you can add the following line in your config.xml (optional):

<preference name="webviewselector-xwalkMaxSdkVersion" value="23" />

This controls which webview engine will be used by default based on Android API level. Up to this preference's value, Crosswalk will be used. Above, it will be system's webview.

If you omit this setting, default value is 23: Crosswalk will be used on all devices up to Android 6.0 and system webview starting with Android 7.0.

Possible permission conflict with other plugins

This plugin requires the WRITE_EXTERNAL_STORAGE permission on Android 4.3 (SDK version 18) and less (further versions are allowing an application to write in its own application-specific directories without it):

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18"/>

If you are using another plugin requiring the same permission but without (or different) condition, Cordova is not able to merge them alone, you have to manually keep the one with the larger scope. More information here.

Usage

WebViewSelector is available on: window.cordova.plugins.WebViewSelector.

WebViewType

Contains available engine ids:

WebViewType.SYSTEM
WebViewType.CROSSWALK

currentEngine

Contains id of current engine:

var ws = window.cordova.plugins.WebViewSelector;
if (ws.currentEngine === ws.WebViewType.CROSSWALK) {
	// ...
}

availableEngines

Array of available engines ids. If Crosswalk is not installed it will only contain WebViewType.SYSTEM.

var ws = window.cordova.plugins.WebViewSelector;
if (ws.availableEngines.length > 1) {
	// we have at least 2 engines available
}

setEngine

Change webview engine. Application needs to be restarted for change to take effect, window.location.reload() being not enough for that. It's possible to kill the application programmatically with navigator.app.exitApp().

var ws = window.cordova.plugins.WebViewSelector;
ws.setEngine(ws.WebViewType.SYSTEM, function (error) {
	if (error) {
		return console.error(error);
	}
	alert('Kill and restart application for change to take effect.');
});

Manual switch

In addition to javascript interface, user can connect his phone to a computer and drop a file named webview.txt containg 0 for system webview or 1 for Crosswalk inside Internal storage/Android/data/yourAppId/files/. This setting will prevail over any other (TODO: it should have an effect only during the first restart and be automatically deleted).

cordova-plugin-webviewselector's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cordova-plugin-webviewselector's Issues

Fail build android

Line 14 in plugin.xml:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18"/>

It conflicts with the same permission without the android SDK version of another plugin.
Solution was remove version dependency in plugin.xml...

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Execution failed for task ':CordovaLib:compileDebugJavaWithJavac'. > Compilation failed; see the compiler error output for details.

I have this error in cordova-android 7.1.0:

:CordovaLib:compileDebugJavaWithJavacC:\Users\pippe\Desktop\project\platforms\android\CordovaLib\src\org\apache\cordova\CordovaWebViewImpl.java:76: error: cannot find symbol
WebViewSelector.updateWebViewPreference(context, preferences);
^
symbol: variable WebViewSelector
location: class CordovaWebViewImpl
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':CordovaLib:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

12 actionable tasks: 5 executed, 7 up-to-date

BUILD FAILED in 29s

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.