Module: Ronin::Web::Browser

Defined in:
lib/ronin/web/browser.rb,
lib/ronin/web/browser/agent.rb,
lib/ronin/web/browser/cookie.rb,
lib/ronin/web/browser/version.rb,
lib/ronin/web/browser/cookie_file.rb

Overview

Automates a Chrome web browser.

Examples

Initialize a headless browser:

browser = Ronin::Web::Browser.new
# ...
browser.quit

Initialize a visible browser:

browser = Ronin::Web::Browser.new(visible: true)
# ...
browser.quit

Opening a temporary browser and automatically quitting:

Ronin::Web::Browser.open do |browser|
  # ...
end

Initializing the browser with a proxy:

browser = Ronin::Web::Browser.new(proxy: "http://proxy.example.com:8080")
# ...

Go to and screenshot a webpage:

Ronin::Web::Browser.open do |browser|
  browser.go_to("https://google.com")
  browser.screenshot(path: "google.png")
end

Intercept all requests:

browser = Ronin::Web::Browser.new
browser.network.intercept
browser.on(:request) do |request|
  puts "> #{request.method} #{request.url}"
  request.continue
end

browser.go_to("https://twitter.com/login")

Intercept all responses for all requests:

browser = Ronin::Web::Browser.new
browser.on(:response) do |exchange|
  puts "> #{exchange.request.method} #{exchange.request.url}"

  puts "< HTTP #{exchange.response.status}"

  exchange.response.headers.each do |name,value|
    puts "< #{name}: #{value}"
  end

  puts exchange.response.body
end

browser.go_to("https://twitter.com/login")

See ferrum for additional documentation.

Defined Under Namespace

Classes: Agent, Cookie, CookieFile

Constant Summary collapse

VERSION =

ronin-web-browser version

'0.1.0'

Class Method Summary collapse

Class Method Details

.new(**kwargs) ⇒ Agent

Initializes the browser agent.

Parameters:

Options Hash (**kwargs):

  • :visible (Boolean) — default: false

    Controls whether the browser will start in visible or headless mode.

  • headless (Boolean) — default: true

    Controls whether the browser will start in headless or visible mode.

  • :proxy (String, URI::HTTP, Addressible::URI, Hash, nil) — default: Ronin::Support::Network::HTTP.proxy

    The proxy to send all browser requests through.

Returns:

  • (Agent)

    A new instance of a headless or visible Chrome browser.



126
127
128
# File 'lib/ronin/web/browser.rb', line 126

def self.new(**kwargs)
  Agent.new(**kwargs)
end

.open(**kwargs) {|browser| ... } ⇒ Agent

Opens a new browser.

Yields:

  • (browser)

    If a block is given, it will be passed the new browser object. Once the block returns, quit will be called on the browser object.

Yield Parameters:

  • browser (Agent)

    The newly created browser object.

Returns:

  • (Agent)

    A new instance of a headless or visible Chrome browser.



143
144
145
# File 'lib/ronin/web/browser.rb', line 143

def self.open(**kwargs,&block)
  Agent.open(**kwargs,&block)
end