Q: Ionic 2: best way to check if is running in browser environment I can't find out in the docs which is the best way to know, in an Ionic 2 app, if it's runnning in the browser (with the ionic serve command) or in the device/emulator.
Actually what I'm doing is check if the window object has an 'plugins' attribute, but I don't know if there is the best way.
if(!window['plugins']) {
//browser
}


A: Oh, I found in the docs the Platform object, which has some methods.
http://ionicframework.com/docs/v2/api/platform/Platform/
One is the is(key), that can match 
import { Platform } from 'ionic-angular';

@Component({...})
export MyPage {
  constructor(platform: Platform) {
    this.platform = platform;
    ...
    if(this.platform.is('core')) {
     //it's in the browser
    }
  }
}


A: while the question is a bit old but still valid - one more option is to use 
https://ionicframework.com/docs/native/device/ - the Device object provides platform property which is equal to 'browser' on browser. The plugin is available only when running webapp via cordova.

A: Just to add a little more to the solution given above, the following does seem to work ok:
import { Platform } from 'ionic-angular';

@IonicPage()
@Component({})
export class WhichPlatformPage {
  isApp: boolean;

  constructor(private platform: Platform) {
    this.isApp = this.platform.is('core') || this.platform.is('mobileweb') ? false : true;
  }
}

ionViewDidLoad() {
  console.log(this.isApp ? 'Running from mobile' : 'Running from the browser');
}

This seems to work fine for me - the main difference from the previous answer is that we are also checking for the 'mobileweb' platform.
Interestingly, if you are using the ionic cordova build browser command, 'mobileweb' becomes 'mobile' - breaking this solution - as this is trying to emulate being on a device as much as possible. This was raised as an issue on GitHub here:
https://github.com/ionic-team/ionic/issues/11557
A solution was given as setting isApp with the following:
this.isApp = !document.URL.startsWith('http');
This works because the mobile apps start their pages with the 'file' protocol. However, if you read into the issue, Ionic are actually recommending against using the cordova browser platform currently, so you would be better off with the original solution.

A: Thought I'd update with an answer that works in case anyone arrives at this question.
This works as of the latest iOS and Android builds:
public isApp(): boolean {
    return (
      document.URL.indexOf('http://localhost') === 0 || // Android
      document.URL.indexOf('ionic') === 0 || // iOS 11+ Ionic Web View
      document.URL.indexOf('https://localhost') === 0 // iOS 10 Ionic Web View
    );
  }

See Ionic Webview readme for more info and caveats.

A: I found this solution resolved in Ionic forum which is using


this.isApp = (!document.URL.startsWith('http') || document.URL.startsWith('http://localhost:8080'));



it may have changes in the future releases though as ios/androd new release change comes
details discussed https://forum.ionicframework.com/t/how-to-determine-if-browser-or-app/89149/15
