Both with and without dev tools open - am I using it wrong?
by user 300386587278049291
Both with and without dev tools open - am I using it wrong?
by user 300386587278049291
Hey what OS are you on? What chrome version are you using?
It’s supposed to return true when you have dev tools open + simulate mobile in Chrome.
If you close dev tools and refresh the page it returns false
. Is that not what happens?
Hey sorry missed these replies - yea it seemed to always be returning true. I ended up implementing a simple test for touch capabilities, but (having not at the Needle source code yet) I was hoping for an actual device test and not just touch capability test. For instance, my current method will return true for a laptop with a touch screen.
by user 300386587278049291
Windows 11 - will report chrome version soon
by user 300386587278049291
So, perhaps surprisingly, there’s no API in browsers to tell you if something is a “mobile” device as it’s pretty much a continuum, feature detection is the way to go
Our isMobileDevice method looks like this and checks for the device having an orientation:
export function isMobileDevice() {
return (typeof window.orientation !== "undefined") || (navigator.userAgent.indexOf('IEMobile') !== -1);
}
So yes, on laptops that have that (I know some Lenovo Yoga do) this would return true too
Checking for touch is another option but typically “device can be orientated differently” is used to determine if it’s “movable/mobile”
Ok thanks for finding that snippet, makes total sense!
by user 300386587278049291