ngCordova InAppBrowser executeScript callback not firing


#1

Hi all,
I’m not able to get working the callback function for executeScript.
This is the code
$cordovaInAppBrowser.executeScript(
{code: “alert(‘hello’)”},
function (values) {
console.log(‘callback’);
}
);
The code:alert(‘hello’) is fired, so I got ‘hello’, but not the console log ‘callback’ (tried also with an alert)
Doing some debug, I saw that the part of the code where the callback should be executed is in cordova.js

msgs is ‘undefined’, and not equal to ‘@Null arguments’ as expected.
So ‘androidExec(success, …)’ is never executed. success is the callback for executeScript.

var msgs = nativeApiProvider.get().exec(bridgeSecret, service, action, callbackId, argsJson);
if (jsToNativeBridgeMode == jsToNativeModes.JS_OBJECT && msgs === "@Null arguments.") {
        androidExec.setJsToNativeBridgeMode(jsToNativeModes.PROMPT);
        androidExec(success, fail, service, action, args);
        androidExec.setJsToNativeBridgeMode(jsToNativeModes.JS_OBJECT);
    }

Any Idea? Thank you in advance.


#2

I’m in the same problem…
I’ve been searching but nothing to fix this yet…

:confused:


#3

I found this, hope helps you! :grin:
The problem is that executeScript is a promise itself, so to make your code working you must write something like this:

$rootScope.$on(’$cordovaInAppBrowser:loadstop’, function (e, event) {
$cordovaInAppBrowser.executeScript(
{
code: “alert(1+1);”
}).then(
function (values) {
alert(‘add completed’);
});
});


#4

Thanks man,
you saved my life :smiley:
Works like a charm. This should be added to ngCordova documentation.


#5

Hi! Great idea, having some similar problems with cordova saying ‘callback is not a function’. Where did you place that code? app.js or in with the service you are using?