ionic-frameworkandroid-webviewcapacitorionic5

Ionic 5 / Capacitor: How to find out if app is running in browser or compiled as native app?


I just want to know, if my Ionic 5 app is running in a browser, or in the webview of a compiled app.

Platform does not work: https://ionicframework.com/docs/angular/platform
It just tells about the device. But when I run it in chrome on an android device, it returns the same platforms as when I run it compiled.

Analysing the URL to check if it the webview url works, but not when using capacitor live reload. Because than it is the same URL like locally in the browser. And by the way, analysing the URL feels like an ugly solution.

Is it really that hard to get this simple and important information, or do I just miss something?

Edit:
Platform output
Chrome in Ubuntu with ionic serve: ["desktop"]
Chrome in Android: ["android", "mobile", "mobileweb"]
Android with capacitor livereload: ["android", "phablet", "mobile", "mobileweb"]
Android compiled: ["android", "phablet", "cordova", "capacitor", "mobile", "hybrid"]


Solution

  • Check Capacitor.getPlatform() If returns web then it’s running as website, if returns ios or android then it’s native.

    Or can also check Capacitor.isNativePlatform().

    https://capacitorjs.com/docs/core-apis/web#getplatform