When using Ionic Serve, you will get a class added to your BODY (http://ionicframework.com/docs/api/utility/ionic.Platform/) that reports if you are using the browser (platform-browser). However, there is no such corresponding support for ionic.Platform (http://ionicframework.com/docs/api/utility/ionic.Platform/). Now - I tend to think adding code for the browser means you are wasting a bit of space in your production code, but it seems like if you support it in one place you should support it here too.
Ok, so you can check using ionic.Platform.platforms. Does it make sense to add a isBrowser method? I think maybe so. If you don't agree, just close, I won't be offended. ;)
you can check one of the following to detect that your on the browser (serve)
ionic.Platform.isWebView();
ionic.Platform.is('browser');
According to the docs, isWebView is: "Check if we are running within a WebView (such as Cordova)"
That to me is not the the same as the browser. Let me see if it works.
Also, ionic.Platform.is is not documented.
So yeah - I tested, it returns false in the browser, as expected by the docs.
isWebView is referring to the native webview cordova runs in, which is about the same as just checking for !!window.cordova which will only be available on device when cordova is run. Will always be false in browser and true on device
Then I'm confused as to why you suggested it. :)
maybe im not understanding what youre asking for... you want your app to know whether or not you are running on broswer such as chrome for testing (ionic serve) or whether or not your running on actual device correct?
If thats true, then what I suggested will be good for what you want, its quite simple either cordova will be available (on device) or it wont (on browser). So ionic gives you a few utility methods as I suggested to give you that information.
ionic.Platform.isWebView() (will be false in ionic serve, true on device)
!!window.cordova (same as above if you are just using cordova rther than phonegap)
ionic.Platform.is('browser') (will be true in ionic serve, false on device)
Ah - ok - you meant check for !isWebView. Heh, ok, that makes sense. I still think a isBrowser() would make sense too.
Also, is('browser') isn't documented, so if it is valid, then it needs to be. I'll add a bug report for it.
I am getting "false" for the above ionic.Platform.is('browser') and "macintel" rather than "browser" for "ionic.Platform.platform()". Is there a way to get just generic "browser" as mentioned above? ...to Clarify, a way that is not semantically confusing such as !isWebView = "this is a browser".
Thanks for opening an issue with us! Since this is more of a question you will be able to get a better answer over at our forum (https://forum.ionicframework.com/) or our slack channel (http://ionicworldwide.herokuapp.com/). Thanks again!
Does it make sense that on my real android app ionic.Platform.isWebView() returns false? I've still found no good way to know when i'm running in a browser (whether on a desktop OR a mobile browser) and when i'm truly an 'app' (IOS or Android). Is there a full-proof way yet?
Same as jeffthompson1971. ionic.Platform.isWebView() returns false in my android device
API is updated http://ionicframework.com/docs/v2/api/platform/Platform/
So now you inject it and call
this.platform.is('mobileweb') || this.platform.is('core') to detect whether or not it's running on a laptop or desktop machine via a web browser.
Open app in device's Chrome browser does not set this.platform.is('mobileweb') to true.
I need cordova for the browser too, not just in android or ios.
For now it seems I can use platform.url() and see if it starts with 'file://'. But it doesn't feel right.
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.
Most helpful comment
Does it make sense that on my real android app ionic.Platform.isWebView() returns false? I've still found no good way to know when i'm running in a browser (whether on a desktop OR a mobile browser) and when i'm truly an 'app' (IOS or Android). Is there a full-proof way yet?