Ionic 5 Angular 在应用程序浏览器中运行 .executeScript() 不起作用



我正在尝试在ionic中打开一个spotify身份验证URL。我正在使用应用内浏览器将用户重定向到那里,然后再重定向回来。(Iab是InappBrowser,this.url是一个工作网址仅供参考(。这是我当前的代码:

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)
})
})

我在我的应用程序上收到错误:"错误类型错误:无法读取未定义的属性'订阅'"。并且警报未显示。

警报不会从 IAB 内部显示(至少在最新版本的 IAB 的 iOS 上(。因此,请使用控制台.log满足您的调试需求。 以下是效果良好的方法:

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");
`
})
})

希望这有帮助。

最新更新