CB-12184 executeScript leads to a null pointer on exception on Android.
This closes #199
This commit is contained in:
parent
1b4859c175
commit
8ab07277cd
@ -222,7 +222,7 @@ The object returned from a call to `cordova.InAppBrowser.open` when the target i
|
|||||||
|
|
||||||
## InAppBrowser.addEventListener
|
## InAppBrowser.addEventListener
|
||||||
|
|
||||||
> Adds a listener for an event from the `InAppBrowser`.
|
> Adds a listener for an event from the `InAppBrowser`. (Only available when the target is set to `'_blank'`)
|
||||||
|
|
||||||
ref.addEventListener(eventname, callback);
|
ref.addEventListener(eventname, callback);
|
||||||
|
|
||||||
@ -338,7 +338,7 @@ function executeScriptCallBack(params) {
|
|||||||
|
|
||||||
## InAppBrowser.removeEventListener
|
## InAppBrowser.removeEventListener
|
||||||
|
|
||||||
> Removes a listener for an event from the `InAppBrowser`.
|
> Removes a listener for an event from the `InAppBrowser`. (Only available when the target is set to `'_blank'`)
|
||||||
|
|
||||||
ref.removeEventListener(eventname, callback);
|
ref.removeEventListener(eventname, callback);
|
||||||
|
|
||||||
@ -438,7 +438,7 @@ The function is passed an `InAppBrowserEvent` object.
|
|||||||
|
|
||||||
## InAppBrowser.executeScript
|
## InAppBrowser.executeScript
|
||||||
|
|
||||||
> Injects JavaScript code into the `InAppBrowser` window
|
> Injects JavaScript code into the `InAppBrowser` window. (Only available when the target is set to `'_blank'`)
|
||||||
|
|
||||||
ref.executeScript(details, callback);
|
ref.executeScript(details, callback);
|
||||||
|
|
||||||
@ -480,7 +480,7 @@ Due to [MSDN docs](https://msdn.microsoft.com/en-us/library/windows.ui.xaml.cont
|
|||||||
|
|
||||||
## InAppBrowser.insertCSS
|
## InAppBrowser.insertCSS
|
||||||
|
|
||||||
> Injects CSS into the `InAppBrowser` window.
|
> Injects CSS into the `InAppBrowser` window. (Only available when the target is set to `'_blank'`)
|
||||||
|
|
||||||
ref.insertCSS(details, callback);
|
ref.insertCSS(details, callback);
|
||||||
|
|
||||||
|
@ -323,29 +323,33 @@ public class InAppBrowser extends CordovaPlugin {
|
|||||||
* which should be executed directly.
|
* which should be executed directly.
|
||||||
*/
|
*/
|
||||||
private void injectDeferredObject(String source, String jsWrapper) {
|
private void injectDeferredObject(String source, String jsWrapper) {
|
||||||
String scriptToInject;
|
if (inAppWebView!=null) {
|
||||||
if (jsWrapper != null) {
|
String scriptToInject;
|
||||||
org.json.JSONArray jsonEsc = new org.json.JSONArray();
|
if (jsWrapper != null) {
|
||||||
jsonEsc.put(source);
|
org.json.JSONArray jsonEsc = new org.json.JSONArray();
|
||||||
String jsonRepr = jsonEsc.toString();
|
jsonEsc.put(source);
|
||||||
String jsonSourceString = jsonRepr.substring(1, jsonRepr.length()-1);
|
String jsonRepr = jsonEsc.toString();
|
||||||
scriptToInject = String.format(jsWrapper, jsonSourceString);
|
String jsonSourceString = jsonRepr.substring(1, jsonRepr.length()-1);
|
||||||
} else {
|
scriptToInject = String.format(jsWrapper, jsonSourceString);
|
||||||
scriptToInject = source;
|
} else {
|
||||||
}
|
scriptToInject = source;
|
||||||
final String finalScriptToInject = scriptToInject;
|
|
||||||
this.cordova.getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@SuppressLint("NewApi")
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
|
||||||
// This action will have the side-effect of blurring the currently focused element
|
|
||||||
inAppWebView.loadUrl("javascript:" + finalScriptToInject);
|
|
||||||
} else {
|
|
||||||
inAppWebView.evaluateJavascript(finalScriptToInject, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
final String finalScriptToInject = scriptToInject;
|
||||||
|
this.cordova.getActivity().runOnUiThread(new Runnable() {
|
||||||
|
@SuppressLint("NewApi")
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||||
|
// This action will have the side-effect of blurring the currently focused element
|
||||||
|
inAppWebView.loadUrl("javascript:" + finalScriptToInject);
|
||||||
|
} else {
|
||||||
|
inAppWebView.evaluateJavascript(finalScriptToInject, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
LOG.d(LOG_TAG, "Can't inject code into the system browser");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user