Class: Puppeteer::BrowserConnector

Inherits:
Object
  • Object
show all
Defined in:
lib/puppeteer/browser_connector.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ BrowserConnector

Returns a new instance of BrowserConnector.



5
6
7
8
9
10
# File 'lib/puppeteer/browser_connector.rb', line 5

def initialize(options)
  @browser_options = Puppeteer::Launcher::BrowserOptions.new(options)
  @browser_ws_endpoint = options[:browser_ws_endpoint]
  @browser_url = options[:browser_url]
  @transport = options[:transport]
end

Instance Method Details

#connect_to_browserPuppeteer::Browser

Returns:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/puppeteer/browser_connector.rb', line 13

def connect_to_browser
  version = Puppeteer::Browser::Version.fetch(connection)
  product = version.product.downcase.include?('firefox') ? 'firefox' : 'chrome'

  result = connection.send_message('Target.getBrowserContexts')
  browser_context_ids = result['browserContextIds']

  Puppeteer::Browser.create(
    product: product,
    connection: connection,
    context_ids: browser_context_ids,
    ignore_https_errors: @browser_options.ignore_https_errors?,
    default_viewport: @browser_options.default_viewport,
    process: nil,
    close_callback: -> { connection.send_message('Browser.close') },
    target_filter_callback: @browser_options.target_filter,
    is_page_target_callback: @browser_options.is_page_target,
  )
end