Callback of InAppBrowser execute script


#1

In the Cordova documentation here https://github.com/apache/cordova-plugin-inappbrowser#inappbrowserexecutescript I see that you can pass execute script a callback function that gets called after the passed script has executed.

I see no mention of this made in the Ionic documentation: http://ionicframework.com/docs/v2/native/inappbrowser/

Is there anyway to attach a callback that receives the return value of the executed script (as mentioned in the cordova link above)?


#2

Looks like I answered my own question. You can do something along the lines of:

let browser = new InAppBrowser('example-url.com');
browser.executeScript({code:'document.cookie;'}).then((cookie)=>console.log(cookie));

Would be nice if this was mentioned in the documentation instead of making no mention of return type (Promise) for executeScript.


#3

Thank you golear. it helped.

Point to note to Ionic2. please add an example usage in documentation.


#4

let browser = new InAppBrowser(‘example-url.com’);
browser.executeScript({code:‘document.cookie;’}).then((cookie)=>console.log(cookie));

I tried but it does’nt work. It opens the browser, but i can’t see any console log


#5

Hi my friend, have you solved your problem?

I have the same problem to solve.

thanks!!!


#6
              const browser = this.inappbrowser.create('example.com','_blank',{location:'no',clearcache:'yes',toolbar:'no'});
              browser.on('loadstop').subscribe(function(event) {
                browser.executeScript({code:'document.cookie;'}).then((cookie)=>{
                       console.log(cookie);
                });
              });

It works


#7

Thank you golear, your answer saved my lots of time.:grinning: