how to detect browser, os and source using user_agent - ruby-on-rails-5

When i printed
request.user_agent
its giving:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36
I need a way to separate browser, os, devise from the above answer and store the in database.

I'd recommend taking a look at one of the many excellent gems in this space

Related

What are the available options to emulate devices using driver.emulateDevice()

I'd like to use Chrome to emulate different devices to run my frontend tests on different emulators. in the documentation, I found the following example
And driver.emulateDevice(375, 812, 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1')
where can I get a list of different options?
That is completely up to you, Karate just takes the string you provide and uses it "as is".
For further research into what that string is all about, you can refer this: https://wicg.github.io/ua-client-hints/

Setting a user agent in Selenium

I'm scraping house rental listings with Selenium using Firefox on a Windows 7 box and have run into a captcha on a website where I have three pages to traverse. Some searching tells me that one of the many techniques I'll have to implement in order to avoid detection is to change the user agent for each request.
I have found Python code on stackoverflow posted as recently as five months ago for doing the same sort of thing in Google Chrome using the following user agent string:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36
But if I go to https://www.whatsmyua.info/ from Firefox on my desktop I see the user agent string is:
Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0
And if I do the same thing using the Tor browser I get this:
Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0
Those two user agent strings don't resemble the Python-style code at all!
Wouldn't putting reference to Windows, AppleWebKit, Chrome and Safari into the user agent string be an obvious tipoff to the bot detector that this is no ordinary browser access?

How do I find the "chromium version" in a chromium based web browser?

For error reporting etc I would like to know the version of chromium used by a chromium based web browser. Can I find that somewhere in the users web browser?
execute "navigator.userAgent" in javascript
it will return a string similar to
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36"
with Chromium as 3rd
Thanks for suggestions about using navigator.userAgent. They might be useful (not sure), but a more safe way seems to use something like
if (typeof chrome === "undefined") {
// Not chromium based, probably Firefox then
}
Any comments on this? #Asesh?

chrome says Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36

I am trying to identify and do some study on what user agent is sending request to our application.
when i execute the request in chrome i see that it says
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"
when i execute it from safari it says
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Safari/602.1.50
when u execute it from mozilla it says
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:49.0) Gecko/20100101 Firefox/49.0
Why does it say "Mozilla/5.0" for all requests and for chrome specifically it lists all mozilla, chrome and safari.
Can any one please explain why is this the case? Thanks.
User agent strings are a mess, and it is very difficult to write code to get accurate information from them. (See this link for a detailed history of why).
If you just want to gather statistics, try adding Google Analytics to your front end, or use a library that specializes in parsing user agent strings on your back end, such as MobileDetect for PHP.
If you want to do something different depending on what features the browser supports, try detecting support for that feature instead of the browser version. Modernizr is great for this.

Sniffing an identifier for the iPhone app used to access a web page

When someone accesses a site via a WebView in an iPhone app, is there a reliable way (JavaScript or server-side) to tell what app is being used? It seems like the user agent string can tell me if it's from Safari or not, but not what precise app is being used if it's not Safari, unless a custom user agent has been specified by the app's programmer (which is not often).
I'd like to be able to tell more precisely what exact app is being used in order to serve [slightly] customised content. The identifier doesn't need to be human-readable, just app-sepcific (so e.g. a bundle ID would be fine).
Example (and not useful) user agents:
From Safari: "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7D11 Safari/528.16"
Most Apps:
"Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Mobile/7D11"
I tried to write just "Nope", but answers are required to be at least 15 characters long...