Just a quick note here but the most recent plugins release included a cool little update to the Device plugin. If you've never used it before, the plugin provides basic information about the app's current working environment, including operating system and device model. In the most recent version, a new property was added: isVirtual
.
As you can probably guess, this property will tell you if you're running on a simulator or a real device. Now while I wouldn't recommend shipping code that uses this normally, during testing it could be real useful. As an example, here is code that simply toggles what kind of camera should be used - the device camera or the photo gallery:
var sourceType = device.isVirtual ? Camera.PictureSourceType.PHOTOLIBRARY:Camera.PictureSourceType.CAMERA;
navigator.camera.getPicture(picDone, picFail, {
sourceType: sourceType,
destinationType:Camera.DestinationType.FILE_URI
});
Not rocket science, but useful. Just to be complete, here is a screen shot of the same code running on my device and simulator.

And if you want, you can grab the source for this demo here: https://github.com/cfjedimaster/Cordova-Examples/tree/master/checkforsim.
For folks curious, running this on Genymotion actually shows that it is considered a simulator, not a real device, even though you run it from the command line like a real device. Surprising.
Archived Comments
Do you know if there is a way to determine if the app is being run in a web browser?
Heh well that depends. Are you talking about:
Just running www via http.
Running via the browser platform.
Running via cordova serve. (Or ionic serve.)
So "run as browser" - the device plugin reports platform is browser. That's easy.
For "run via http" and ionic serve, the device plugin doesn't exist at all.
You could check for window.cordova - it won't exist.
All of the above is what I was looking for. ng-cordova-oauth is not compatible in a browser and I want to make sure no one tries to use such.
Eliminates a lot of wasted time trying to troubleshoot someones problem when the result is they are using a service that is clearly outlined in the README as not compatible.
I'd check for window.cordova.
I'd have to re-evaluate, but I think window.cordova wasn't enough when it came to ionic serve.
I'll get back to you.
don't allow if: window.cordova is null OR device.platform is browser.
Will give it a shot. Thanks!