Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
103 views
in Technique[技术] by (71.8m points)

How to use the Capacitor Browser API to access url in the browser

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']);
                            }
                        });

But recently the payment url provider has blocked inline access , so i am not able to use inApp browser to complete the process, so i decided to try Browser Api from capacitor, but im not sure how to access the url through event handler to be specific i want to do this

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

But using Browser api, im not able to access the event (finished is undefined)

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

Browser.addListener('browserFinished',(finished) => { console.log("thisi is url at finish" + finished ) })

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

Any suggestion how to check if the browser url is redirect to a specific point?

question from:https://stackoverflow.com/questions/65831473/how-to-use-the-capacitor-browser-api-to-access-url-in-the-browser

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Capacitor's Browser plugin uses Safari View Controller on iOS and Chrome Custom Tabs on Android, none of those components provide the loaded url, so the plugin can't provide it neither.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...