Skip to content

Add support for emulating devices for hover and pointer css media queries #282

Closed as not planned

Description

@simonjnesta

The pointer, any-pointer, hover and any-hover media queries allow you to style a page based on the available input devices. Currently there is no way I can see to change how cuprite/ferrum responds to these queries.

E.g. I have a site where the navigation is different based on whether you have a mouse or not. Currently, only the touch version of the site can be tested because @media (any-hover: hover) will never work in a cuprite-driven browser.

Activity

  1. phylor commented on Dec 4, 2024

    @phylor
    Contributor

    If you can live with always having the same setting, you can set the browser option blink-settings for this.

    For example:

      Capybara::Cuprite::Driver.new(app, {
                                      browser_options: {
                                        'blink-settings': 'primaryPointerType=4'
                                      }
                                    })
    
  2. route commented on Oct 15, 2026

    @route
    Member

    This isn't a Cuprite issue: it's how Chrome reports input devices. When there's no mouse, as in headless Chrome on Linux or in Docker, Chrome matches (hover: none) and (pointer: none). CDP can't override these, since Emulation.setEmulatedMedia ignores hover and pointer, so the fix is to start Chrome with flags that declare a mouse:

    Capybara::Cuprite::Driver.new(app, browser_options: {
      "blink-settings" => "primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4"
    })

    primaryPointerType=4 alone isn't enough, because it only fixes pointer. The hover values are needed for hover and any-hover. With all four set, Chrome 155 on Linux matches (hover: hover), (any-hover: hover), (pointer: fine) and (any-pointer: fine).

    If you connect to a remote browser with url:, browser_options doesn't apply. In that case, pass the same --blink-settings=... flag to the Chrome started in the container.

    For the touch version, the new emulate: option from #338 (e.g. emulate: :iphone_14) or mobile: true switches Chrome to (hover: none) and (pointer: coarse).

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions