ionic.Platform.platform() return incorrect in Chrome


#1

ionic.Platform.platform(), when run in ionic.Platform.ready(), under Chrome using ionic serve, used to return “win32”; now returns “ios”. This is on a windows 10 machine, and I did a “ionic platform add android” on the project.

  1. ionic --version = 1.7.14
  2. create a sidemenu project (ionic start sidemenu), in the controllers.js add:

ionic.Platform.ready(function() {
console.log(ionic.Platform.platform()); // Chrome “ionic serve” returns “ios”
});


#2

Looks like you might have device mode debugging enabled:


Ctrl + Shift + M to toggle it


#3

Thanks for the reply. I get “ios” whether it is enabled or disabled. Changed the default to Firefox returns win32. MS Edge - the people who gave us win32 - returns “edge”.


#4

Well ok. I just looked further into this. ionic.Platform.platform() doesn’t seem to give very reliable results. https://github.com/driftyco/ionic/issues/4306

Better way to check wehter its running in a browser or not is this:
if (window.cordova) {
// running on device/emulator
} else {
// running in dev mode
}

ionic.Platform.platform() should work fine on a mobile device.