Class: Capybara::Lightpanda::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/lightpanda/options.rb

Constant Summary collapse

DEFAULT_TIMEOUT =
ENV.fetch("LIGHTPANDA_DEFAULT_TIMEOUT", 15).to_i
DEFAULT_PROCESS_TIMEOUT =
ENV.fetch("LIGHTPANDA_PROCESS_TIMEOUT", 10).to_i
DEFAULT_HANDSHAKE_TIMEOUT =

Bounded budget for the WebSocket TCP+Upgrade handshake. Distinct from ‘timeout` (per-CDP-command budget) because a handshake either succeeds in a few hundred ms or won’t — bleeding the full command budget into it just delays the eventual failure.

ENV.fetch("LIGHTPANDA_HANDSHAKE_TIMEOUT", 5).to_i
DEFAULT_HOST =
"127.0.0.1"
DEFAULT_PORT =
9222
DEFAULT_WINDOW_SIZE =
[1024, 768].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Options

Returns a new instance of Options.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/capybara/lightpanda/options.rb', line 23

def initialize(options = {})
  @host = options.fetch(:host, DEFAULT_HOST)
  @port = options.fetch(:port, DEFAULT_PORT)
  @timeout = options.fetch(:timeout, DEFAULT_TIMEOUT)
  @handshake_timeout = options.fetch(:handshake_timeout, DEFAULT_HANDSHAKE_TIMEOUT)
  @process_timeout = options.fetch(:process_timeout, DEFAULT_PROCESS_TIMEOUT)
  @window_size = options.fetch(:window_size, DEFAULT_WINDOW_SIZE)
  @browser_path = options[:browser_path]
  @headless = options.fetch(:headless, true)
  @ws_url = options[:ws_url]
  @logger = parse_logger(options[:logger])
end

Instance Attribute Details

#browser_pathObject

Returns the value of attribute browser_path.



19
20
21
# File 'lib/capybara/lightpanda/options.rb', line 19

def browser_path
  @browser_path
end

#handshake_timeoutObject

Returns the value of attribute handshake_timeout.



19
20
21
# File 'lib/capybara/lightpanda/options.rb', line 19

def handshake_timeout
  @handshake_timeout
end

#headlessObject

Returns the value of attribute headless.



19
20
21
# File 'lib/capybara/lightpanda/options.rb', line 19

def headless
  @headless
end

#hostObject

Returns the value of attribute host.



19
20
21
# File 'lib/capybara/lightpanda/options.rb', line 19

def host
  @host
end

#loggerObject

Returns the value of attribute logger.



19
20
21
# File 'lib/capybara/lightpanda/options.rb', line 19

def logger
  @logger
end

#portObject

Returns the value of attribute port.



19
20
21
# File 'lib/capybara/lightpanda/options.rb', line 19

def port
  @port
end

#process_timeoutObject

Returns the value of attribute process_timeout.



19
20
21
# File 'lib/capybara/lightpanda/options.rb', line 19

def process_timeout
  @process_timeout
end

#timeoutObject

Returns the value of attribute timeout.



19
20
21
# File 'lib/capybara/lightpanda/options.rb', line 19

def timeout
  @timeout
end

#window_sizeObject

Returns the value of attribute window_size.



19
20
21
# File 'lib/capybara/lightpanda/options.rb', line 19

def window_size
  @window_size
end

#ws_urlObject



36
37
38
# File 'lib/capybara/lightpanda/options.rb', line 36

def ws_url
  @ws_url || "ws://#{host}:#{port}/"
end

Instance Method Details

#to_hObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/capybara/lightpanda/options.rb', line 44

def to_h
  h = {
    host: host,
    port: port,
    timeout: timeout,
    handshake_timeout: handshake_timeout,
    process_timeout: process_timeout,
    window_size: window_size,
    browser_path: browser_path,
    headless: headless,
    logger: logger,
  }
  h[:ws_url] = @ws_url if @ws_url
  h
end

#ws_url?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/capybara/lightpanda/options.rb', line 40

def ws_url?
  !@ws_url.nil?
end