TheShalit TheShalit - 5 months ago 46
Javascript Question

Check if ionic app is in dev serve mode(browser)

I use

ionic serve
to run my app on localhost.

how can I know when I'm in browser and not in android?

I tried:

navigator.platform // MacIntel
navigator.platforms // undefined'BROWSER') // false
navigator.userAgent // ...iPhone... => i'm in chrome device mode

Thank you!


There's probably more than one way to do it, but a simple one is that cordova will only be defined on Android/iOS so you could do

if (window.cordova) {
  // running on device/emulator
} else {
  // running in dev mode