fnando / browser

Do some browser detection with Ruby. Includes ActionController integration.
MIT License
2.46k stars 362 forks source link

Filtering out of bots? #42

Closed rceee closed 10 years ago

rceee commented 11 years ago

It looks like some of the browser check methods are doing some degree of filtering... e.g.,

def safari?
  ua =~ /Safari/ && ua !~ /Chrome|CriOS|PhantomJS/
end

But is this functionality intended to just double-check the user-agent, or is it designed to filter against bots that may return multiple browser name responses?

Is there a way to utilize the combinations in such a way to estimate whether the browser is human or bot, e.g.,

def notbot?
  (browser.webkit? || browser.firefox? || browser.ie? || browser.opera? || browser.safari? || browser.chrome?) && !browser.compatibility_view?
end
fnando commented 10 years ago

You can monkey-patch the Browser class with your custom methods.

class Browser
  def notbot?
    # your logic
  end
end

Also, the v0.3.0 contains some basic bot verification through the Browser#bot? method.