简体   繁体   中英

Ionic 5 Angular Running In App Browser .executeScript() not working

I am trying to open a spotify authentication URL in ionic. I am using in-app browser to redirect the user there and then back. ( Iab is InappBrowser and this.url is a working url FYI). Here is my current code:

const browser = this.Iab.create(this.url,"_blank",'location=yes')
    browser.on('loadstop').subscribe(function(){
      browser.executeScript({code:'alert("hello world")'}).then((cookie) =>{
      console.log(cookie)
    })
})

I am getting the error: "ERROR TypeError: Cannot read property 'subscribe' of undefined" on my app. And the alert is not showing.

Alerts do not show up from within the iab (atleast on iOS for the latest version of the IAB). So please use console.log for your debugging needs. The following is what works well:

 this.browser = this.iab.create(url,"_blank","hidden=yes,toolbar=no");
 this.browser.on('loadstop').subscribe(event => {
    console.log("load stop", event)
    this.browser.show();

    this.browser.executeScript({
      code: ` //alert will not work here 
            console.log("HELLO");
      `
    })
})

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM