diff --git a/lib/ronin/web/browser.rb b/lib/ronin/web/browser.rb index dc85084..86da56e 100644 --- a/lib/ronin/web/browser.rb +++ b/lib/ronin/web/browser.rb @@ -117,6 +117,9 @@ module Browser # @option kwargs [Boolean] headless (true) # Controls whether the browser will start in headless or visible mode. # + # @option kwargs [String, nil] url + # Provides url for browser to navigate to after initialization. + # # @option kwargs [String, URI::HTTP, Addressible::URI, Hash, nil] :proxy (Ronin::Support::Network::HTTP.proxy) # The proxy to send all browser requests through. # diff --git a/lib/ronin/web/browser/agent.rb b/lib/ronin/web/browser/agent.rb index 98b470d..0c09c78 100644 --- a/lib/ronin/web/browser/agent.rb +++ b/lib/ronin/web/browser/agent.rb @@ -39,7 +39,7 @@ class Agent < Ferrum::Browser attr_reader :proxy # - # Initializes the browser agent. + # Initializes the browser agent, and optionally navigates to the url, if provided. # # @param [Boolean] visible # Controls whether the browser will start in visible or headless mode. @@ -50,12 +50,16 @@ class Agent < Ferrum::Browser # @param [String, URI::HTTP, Addressible::URI, Hash, nil] proxy # The proxy to send all browser requests through. # + # @param [String, nil] url + # Provides url for browser to navigate to after initialization. + # # @param [Hash{Symbol => Object}] kwargs # Additional keyword arguments for `Ferrum::Browser#initialize`. # def initialize(visible: false, headless: !visible, proxy: Ronin::Support::Network::HTTP.proxy, + url: nil, **kwargs) proxy = case proxy when Hash, nil then proxy @@ -83,6 +87,7 @@ def initialize(visible: false, @proxy = proxy super(headless: headless, proxy: proxy, **kwargs) + go_to(url) if url end # diff --git a/spec/agent_spec.rb b/spec/agent_spec.rb index 1ffc278..59911c1 100644 --- a/spec/agent_spec.rb +++ b/spec/agent_spec.rb @@ -21,6 +21,18 @@ after { Ronin::Support::Network::HTTP.proxy = nil } end + context "when given the url: keyword argument" do + let(:url) { 'https://example.com/' } + subject { described_class.new(url: url) } + + it 'navigates to the url' do + expect(subject.url).to eql(url) + expect(subject.current_url).to eql(url) + end + + after { subject.quit } + end + context "when given the proxy: keyword argument" do let(:proxy_host) { 'example.com' } let(:proxy_port) { 8080 }