如何使用电容浏览器API访问浏览器中的url

时间:2021-01-21 16:17:57

标签: capacitor

I have a working code as such 
 this.paymentApiService.createPaymentMethod(paymentMethodDto)
            .subscribe((payment) => {
                    this.paymentForm = null;
                    if (payment.url) {
                        this.paymentForm = null;
                        console.log('Loading dismissed!');
                        loading.onDidDismiss();
                        const abcd = this.inAppBrowser.create(payment.url, '_blank');
                        abcd.on('loadstop').subscribe((event) => {
                            if (event.url.includes('/credit-card/wait')) {
                                abcd.close();
                                this.modalController.dismiss();
                                this.router.navigate(['credit-card/wait']);
                            } else if (event.url.includes('/credit-card/failure')) {
                                abcd.close();
                                this.modalController.dismiss();
                                this.router.navigate(['credit-card/failure']);
                            }
                        });

但最近支付 url 提供商阻止了内联访问,所以我无法使用 inApp 浏览器来完成该过程,所以我决定尝试使用电容浏览器 Api,但我不确定如何通过事件处理程序访问 url 具体来说,我想这样做

abcd.on('loadstop').subscribe((event) => {
                                if (event.url.includes('/credit-card/wait')) {
                                    abcd.close();

但是使用浏览器api,我无法访问该事件(完成未定义)

 Browser.open({ url: payment.url });

Browser.addListener('browserFinished',(finished) => { console.log("thisi 是完成时的 url" + 完成 ) })

     Browser.addListener('browserPageLoaded',(finished: any) =>  {
         console.log("thisi is url at page loaded" +    finished )
     })

关于如何检查浏览器 url 是否重定向到特定点的任何建议?

1 个答案:

答案 0 :(得分:1)

Capacitor 的浏览器插件在 iOS 上使用 Safari 视图控制器,在 Android 上使用 Chrome 自定义标签,这些组件都没有提供加载的 url,因此插件也无法提供。