Giter Site home page Giter Site logo

browserslist-useragent-ruby's Issues

How to use in a Rails/Webpacker environment?

The readme states to include the browsers.json generating code in the webpack config, however in a Rails/Webpacker environment there is no straightforward webpack config js file. Is this gem compatible with Webpacker?

ArgumentError on old versions of Chrome

We're using this gem and on the following Chrome 53 UA string:

Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/535.14.61 (KHTML, like Gecko) Chrome/53.5.0289.5916 Safari/534.43

We received the following error:

ArgumentError
53.5.0289 is not a valid SemVer Version (http://semver.org)

It seems that this is definitely an allowable version number. Could I suggest using Gem::Version to parse the version number instead? I also think this gem should define its own exception class if there's a true problem with parsing as well instead of just throwing an ArgumentError, which is very broad and could potentially mask lots of other issues.

Rename dir

The for inside lib/ must have the same name as gem. Otherwise you will have name conflict with some browserslist in the future.

Improve docs

  1. Fix first section ๐Ÿ˜„
  2. Add link to Browserslist
  3. Describe Browserslist in one sentence
  4. Add benefits (that Browserslist is used in AutoprefixerRails and many other front-end tools).
  5. Add code examples
  6. I think you can remove gem install step. Bundler is everywhere.

Great idea to create a gem. Feel free to ask me about open source promotion.

Opera Mobile on Android not detected

  • I'm submitting a ...

    • bug report
  • What is the current behavior?
    matcher.browser? returns false even though it is in my .browserlistrc

  • What is the expected behavior?
    matcher.browser? should return true

  • What is the motivation / use case for changing the behavior?
    The current behaviour seems incorrect

  • Please tell us about your environment:

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)
    Seems to fail because of a whitespace:

    30: def browser?                                                                                                                                       
    31:   target_browser = user_agent[:family].downcase                                                                                                    
 => 32:   queries.key?(target_browser)                                                                                                                     
    33: end                                                                                                                                                
                                                                                                                                                           
[1] pry(#<BrowserslistUseragent::Match>)> target_browser                                                                                                   
=> "opera mobile"                                                                                                                                          
[2] pry(#<BrowserslistUseragent::Match>)> queries                                                                                                          
=> {"chrome"=>["81", "83", "81", "80"],                                                                                                                    
 "firefox"=>["68", "78", "77", "76", "68"],                                                                                                                
 "qqandroid"=>["10.4"],                                                                                                                                    
 "ucandroid"=>["12.12"],                                                                                                                                   
 "android"=>["81"],                                                                                                                                        
 "baidu"=>["7.12"],                                                                                                                                        
 "edge"=>["83", "81", "18"],                                                                                                                               
 "ios"=>["13.4-13.5", "13.3", "12.2-12.4"],                                                                                                                
 "kaios"=>["2.5"],                                                                                                                                         
 "operamini"=>["all"],                                                                                                                                     
 "operamobile"=>["46"],                                                                                                                                    
 "opera"=>["69", "68"],                                                                                                                                    
 "safari"=>["13.1", "13"],                                                                                                                                 
 "samsung"=>["12.0", "11.1-11.2"]}  

A potential solution could be to adjust the resolver.rb to handle opera mobile.

False negatives matching Safari 11.1

First off, thanks for this package. It's been extremely helpful in our efforts to standardize supported browsers within our team.

I'm having an issue with a specific browser. Given the following code in Rails:

matcher = BrowserslistUseragent::Match.new(
      ['safari 11.1'],
      'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15'
    )

logger.debug "#{matcher.browser?}"
logger.debug "#{matcher.version?(allow_higher: true)}"

Output is

false
false

Same thing with last 2 Safari versions query (or any last X Safari versions query for that matter). (just realized the browsers.json is likely created to avoid matching against this syntax)

I tried the same user agent in the node package (browserslist-useragent) and it returned true.

iOS Safari version detection

This is potentially a bug, or some imprecision/ambiguity in one of the code comments.

There are two cases related to resolving the iOS version within resolver.rb

# Case A: For Safari, Chrome and others browsers on iOS
# that report as Safari after stripping tags
family = 'iOS' if agent.family.include?('Safari') && agent.os.family == 'iOS'
# Case B: The browser on iOS didn't report as safari,
# so we use the iOS version as a proxy to the browser
# version. This is based on the assumption that the
# underlying Safari Engine used will be *atleast* equal
# to the iOS version it's running on.
if agent.os.family == 'iOS'
return {
family: 'iOS',
version: VersionNormalizer.new(agent.os.version.to_s).call
}
end

Case B explains;

Case B: The browser on iOS didn't report as safari, so we use the iOS version as a proxy to the browser version. This is based on the assumption that the underlying Safari Engine used will be atleast equal to the iOS version it's running on.

However the condition used for this is simply

if agent.os.family == 'iOS'

As such, whether the browser identifies as Safari or not, the version number is set to the os version; making Case A redundant,

The comment would seem to suggest that there should be logic that is specifically checking for the absence of Safari;

if !agent.family.include?('Safari') && agent.os.family == 'iOS'

As background, this stems from the following real-world example;

ua = 'Mozilla/5.0 (iPad; CPU OS 12_5_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.2 Mobile/15E148 Safari/604.1'
matcher = BrowserslistUseragent::Match.new(['ios_saf 12.2-12.5'], ua)
matcher.browser? && matcher.version?(allow_higher: true)

=> true

Where although it is Safari and iOS, it is replacing the browser version 12.1.2 with the os version 12.5.6 and returning a match.
This potentially doesn't match the expectation based on the Case B comment.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.