I noticed something strange with WKWebView user agents.
If I try setting it as
webViewConfiguration.defaultWebpagePreferences.preferredContentMode = .mobile
webViewConfiguration.applicationNameForUserAgent = "MYIOSAPP/\(appVersion)"
I get this:
Mozilla/5.0 (iPad; CPU OS 15_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) MYIOSAPP/1.0
However if I set the customUserAgent like so:
webView.customUserAgent = (webView.value(forKey: "userAgent") ?? "") + "MYIOSAPP/\(appVersion)"
I get this:
Mozilla/5.0 (iPad; CPU OS 15_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MYIOSAPP/1.0
What is causing it to lose the Mobile part of the user agent? Also why does it even need it if it already has the iOS version number in the string?
Related
I am working with Geolocation and I have a string of User Agent saved into my database as shown below:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
In this case of the string above, the information I would like to output in my views is Macintosh; Intel Mac OS X 10_13_6. So, in the frontend/views, I don't want to output the whole data as its in the database. All I want to pick from this information is just to show the devise the user used to login into the application, and I do not know how I will show only what I want. Any help or pointer to what I should do will be appreciated.
view
.row
.panel.panel-primary
.panel-heading
span = t('admin_header.traffics')
.panel-body
= table_for(#traffic, class: 'table table-condensed table-hover') do |t|
- t.column :ua, 'Device Used', class: 'col-xs-1' # But this shows all the string which I do not want, I only want specific details from it.
Here is the code that saves User Agent string into the Database:
def save_signup_history(member_id)
SignupHistory.create(
member_id: member_id,
email: #member.email,
ip: request.remote_ip,
accept_language: request.headers["Accept-Language"],
ua: request.headers["User-Agent"], #Here is User Agent
login_location: get_ip_location
)
end
The only thing I can think of is to use .remove method, but I don't think its a best solution to my problem.
How about using the user_agent gem?
In the specific example you gave you could use:
user_agent = request.env['HTTP_USER_AGENT']
user_agent.match(/\(.*?\)/)[0]
However that may not cover every case, and either using a gem or code which accounts for the various options is your best bet.
You can use the scan method to get the string you need.
Example:
user_agent = Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
then,
user_agent.scan(/Mac.*_6/)
should give you your desired string. You can modify it as per your requirements.
We are using Nylas api to get Access token for different type of Email account like Gmail, Outlook.. But We couldn't authenticate for Gmail.
let myURL = URL(string: getNylasAuthUrl())
let userAgent = getUserAgentParams()
webView.customUserAgent = userAgent
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
got below error
Finally found a way, by setting User-Agent, we could do authentication for gmail from post
Tried below User-agents but didn't help
let userAgent = "Mozilla/5.0 (Apple \(Utils.getDeviceModel()) ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
let userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
let userAgent = "Mozilla/5.0 (Google) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
Finally, I found the working user-agent.
let userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_2 like Mac OS X)
AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14F89 Safari/602.1"
If you want to Google auth via Webview, use this user-agent especially for getting access token.
I am trying to decipher this information from user-agent string on a node.js server based on Sails.js framework.
I have access to user-agent in req.headers["user-agent"]
Currently I am using this function to segregate iPhone, iPad and Android devices.
function findPlatform(userAgent){
var iphoneReg = /\biphone\b/gi;
var ipadReg = /\bipad\b/gi;
var androidReg = /\bandroid\b/gi;
if(!userAgent){
sails.log.error("cant infer user agent");
return "others";
}
if(userAgent.search(androidReg) > -1){
return "android";
}
else if(userAgent.search(iphoneReg) > -1){
return "iphone";
}
else if(userAgent.search(ipadReg) > -1){
return "ipad";
}
else {
return "others";
}
}
However, I also need to segregate between mobile app and mobile browser for both android and iOS. I was looking at certain requests and could see that user-agent from mobile app looks like this:
"Mozilla/5.0 (Linux; Android 5.0; Lenovo A7000-a Build/LRX21M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/45.0.2454.95 Mobile Safari/537.36"
While from mobile browser, it looked like this:
"Mozilla/5.0 (Linux; Android 4.4.4; MI 4W Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.76 Mobile Safari/537.36"
Can I user a regex to match keyword "Version" to identify the request as coming from app ? What about iOS ?
I want to detect what operating system the client is using. I can detect whether it is mobile or desktop. How can I detect whether it is using IOS or Android?
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/28.0.1500.52 Chrome/28.0.1500.52 Safari/537.36
Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko)
Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10
Use a gem like 'browser' or one like it.
https://github.com/fnando/browser
browser = Browser.new(:ua => "some string", :accept_language => "en-us")
browser.name # readable browser name
browser.version
browser.safari?
browser.opera?
browser.chrome?
browser.mobile?
browser.tablet?
browser.firefox?
browser.ie?
browser.ie6? # this goes up to 10
browser.modern? # Webkit, Firefox 17+, IE 9+ and Opera 12+
browser.platform # return :mac, :windows, :linux or :other
browser.mac?
browser.windows?
browser.linux?
browser.blackberry?
browser.meta # an array with several attributes
browser.to_s # the meta info joined by space
There are several ways to change the user agent header send by UIWebView. However the value of window.navigator.userAgent retrieved by JS on any page always contains the same value, something like "Mozilla/5.0 (iPad; U; CPU OS 4_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile/8C134".
Is there any way to change that value without having to modify the HTML response (and insert some JS)?
Thanks in advance!