Skip to content

[Feature Request] Add support for detecting headless browsers #562

Description

@pioz

Hi!

I’d like to request support for detecting headless browsers.

For example, Chrome running in headless mode may expose a user agent like this:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/143.0.7499.4 Safari/537.36

At the moment, it would be useful to have a simple way to detect this through the gem, for example:

browser.headless?

This could return true when the user agent contains known headless browser identifiers such as HeadlessChrome.

Possible use cases:

  • Detecting automated/headless traffic
  • Adjusting behavior for browser automation tools
  • Improving analytics or request classification
  • Handling bots or test environments differently

Example expected behavior:

browser = Browser.new(
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/143.0.7499.4 Safari/537.36"
)

browser.chrome?    # true
browser.headless?  # true

Would you be open to adding a headless? method, or something similar, to detect this kind of browser?

Thanks!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions