Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

webdriver-user-agent

Package Overview
Dependencies
Maintainers
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webdriver-user-agent

  • 7.9
  • Rubygems
  • Socket score

Version published
Maintainers
4
Created
Source

Webdriver::User::Agent

A helper gem to emulate populate device user agents and resolutions when using webdriver

Installation

Add this line to your application's Gemfile:

gem 'webdriver-user-agent'

And then execute:

$ bundle

Or install it yourself as:

$ gem install webdriver-user-agent

Usage

provides a UserAgent.driver method to return a new web-driver with user agent and screen resolution mimicking a mobile device.

Options

  • :browser
    • :firefox (default)
    • :chrome
    • :safari
  • :agent
    • :iphone (default)
    • :ipad
    • :android_phone
    • :android_tablet
    • :random
  • :orientation
    • :portrait (default)
    • :landscape

Example using selenium-webdriver

require 'selenium-webdriver'
require 'webdriver-user-agent'
driver = Webdriver::UserAgent.driver(:browser => :chrome, :agent => :iphone, :orientation => :landscape)
driver.get 'http://tiffany.com'
driver.current_url.should == 'http://m.tiffany.com/International.aspx'

Example using random user agent

require 'selenium-webdriver'
require 'webdriver-user-agent'
driver = Webdriver::UserAgent.driver(:agent => :random)
driver.execute_script('return navigator.userAgent')
# random agent like "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.2) Gecko/20010726 Netscape6/6.1"

Example using watir

require 'watir'
require 'webdriver-user-agent'
driver = Webdriver::UserAgent.driver(:browser => :chrome, :agent => :iphone, :orientation => :landscape)
browser = Watir::Browser.new(driver)
browser.goto 'tiffany.com'
browser.url.should == 'http://m.tiffany.com/International.aspx'

A note on Safari

In our testing, it doesn't work well. Sometimes Safari Technology Preview works better, sometimes only Safari works at all. And as of May 2021, our ability to write user agent strings and languages for either flavor of Safari seems not to work on macOS Big Sur/Safari 14.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

FAQs

Package last updated on 25 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc