Class: Unmagic::Browser::Driver::Local

Inherits:
Base
  • Object
show all
Defined in:
lib/unmagic/browser/driver/local.rb

Overview

Chrome on this machine.

The development default, and the only driver where you can watch what's happening: headless: false opens a real window, which is how a person gets to solve a captcha mid-session and hand control back.

Examples:

Unmagic::Browser.new(driver: Unmagic::Browser::Driver::Local.new(headless: false))

Constant Summary collapse

DEFAULT_ARGS =

Chrome flags that only make sense for automation. --no-sandbox is what lets Chrome run as root inside a container, which is where CI lives.

[
  "--disable-dev-shm-usage",
  "--no-sandbox",
  "--disable-gpu",
].freeze

Constants inherited from Base

Base::DEFAULT_TIMEOUT, Base::WAIT_UNTIL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#close, #html, #markdown, #name, #open_connection, #pdf, #screenshot

Constructor Details

#initialize(headless: true, executable_path: nil, args: [], slow_mo: nil) ⇒ Local

Returns a new instance of Local.

Parameters:

  • headless (Boolean) (defaults to: true)

    false opens a window you can watch and click

  • executable_path (String, nil) (defaults to: nil)

    a specific Chrome binary

  • args (Array<String>) (defaults to: [])

    extra Chrome flags, added to DEFAULT_ARGS

  • slow_mo (Integer, nil) (defaults to: nil)

    milliseconds to pause between operations, to watch a run



39
40
41
42
43
44
45
# File 'lib/unmagic/browser/driver/local.rb', line 39

def initialize(headless: true, executable_path: nil, args: [], slow_mo: nil)
  super()
  @headless = headless
  @executable_path = executable_path
  @args = (DEFAULT_ARGS + args).uniq.freeze
  @slow_mo = slow_mo
end

Instance Attribute Details

#argsArray<String> (readonly)

Returns the flags Chrome is launched with.

Returns:

  • (Array<String>)

    the flags Chrome is launched with



33
34
35
# File 'lib/unmagic/browser/driver/local.rb', line 33

def args
  @args
end

#executable_pathString? (readonly)

Returns the Chrome binary to run, or nil to let Puppeteer find one.

Returns:

  • (String, nil)

    the Chrome binary to run, or nil to let Puppeteer find one



30
31
32
# File 'lib/unmagic/browser/driver/local.rb', line 30

def executable_path
  @executable_path
end

#headlessBoolean (readonly)

Returns whether Chrome runs without a window.

Returns:

  • (Boolean)

    whether Chrome runs without a window



27
28
29
# File 'lib/unmagic/browser/driver/local.rb', line 27

def headless
  @headless
end