Capacitor: bug (Capacitor Browser): browserFinished | browserPageLoaded does not return anything

Created on 3 Jun 2020  ·  8Comments  ·  Source: ionic-team/capacitor

Bug Report

Capacitor Version

npx cap doctor output:

npx cap doctor
   Capacitor Doctor 

Latest Dependencies:
  @capacitor/cli: 2.1.2
  @capacitor/core: 2.1.2
  @capacitor/android: 2.1.2
  @capacitor/ios: 2.1.2

Installed Dependencies:
  @capacitor/ios not installed
  @capacitor/cli 1.4.0
  @capacitor/core 2.1.2
  @capacitor/android 2.1.2
[success] Android looking great! 👌

Affected Platform(s)

  • [X] Android
  • [ ] iOS
  • [ ] Electron
  • [X] Web

Current Behavior


This event doesnt return anything in callback

Expected Behavior


It should return something

Sample Code or Sample Application Repo

async openUrl() {
        if (Capacitor.isPluginAvailable('Browser')) {
            await Browser.open({
                url: 'http://capacitor.ionicframework.com/',
            });
            Browser.addListener('browserFinished', (err, result) => {
                console.log(err, result, 'browserFinished');
                if (err) {
                    return console.warn('[Browser-Finished] Something went wrong!');
                }
                console.log(result, 'Browser Finished Listen Result');
            });
            Browser.addListener('browserPageLoaded', (err, result) => {
                console.log(err, result, 'BrowserPageLoad');
                if (err) {
                    return console.warn('[Browser-PageLoad] Something went wrong!');
                }
                console.log(result, 'Browser PageLoad Listen Result');
            });
        } else {
            console.log('capacitor browser is not available');
        }
    }

Reproduction Steps

Other Technical Details

npm --version output: 6.9.0

node --version output: v10.16.3

pod --version output (iOS issues only):

Other Information

enhancement feature request

Most helpful comment

If not returning anything is the expected behavior, then the docs should not show (info: any) => void as the listener function's signature. It is very misleading.

All 8 comments

This is not a bug, they don't return anything on any platform, so tagging as feature request.

Issues tagged with feature request are closed but tracked for👍 reactions to gauge interest.

Would be good to know what do you expect them to return, but the native API is very limited, so there is not really a lot of things to return.

In the return we should get changed url so we can use it.

That's not provided by SFSafariViewController nor by Chrome Custom Tabs that the plugin uses, so not really possible.

Ok thanks Man to inform.

I would like to have same features in this capacitor plugin like we have in cordova in-app browser

As I said, it's not possible because this plugin uses SFSafariViewController on iOS and Chrome Custom Tabs, and while it has some advantages over using a webview (what InAppBrowser plugin uses), it also has some limitations, like not being able to know the urls you are loading, or not being able to inject javascript or css. This is by design because Apple and Google thing those features affect security and privacy and the focus of those components is precisely improving the security and privacy.

So if you need those features, keep using cordova's InAppBrowser plugin or create a Capacitor plugin that uses a webview to load the content.

okay i get it. thank you for explanation

If not returning anything is the expected behavior, then the docs should not show (info: any) => void as the listener function's signature. It is very misleading.

Was this page helpful?
0 / 5 - 0 ratings