Class: Puppeteer::Puppeteer

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

Instance Method Summary collapse

Constructor Details

#initialize(project_root:, preferred_revision:, is_puppeteer_core:) ⇒ Puppeteer

Returns a new instance of Puppeteer.

Parameters:

  • project_root (String)
  • prefereed_revision (String)
  • is_puppeteer_core (String)


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

def initialize(project_root:, preferred_revision:, is_puppeteer_core:)
  @project_root = project_root
  @preferred_revision = preferred_revision
  @is_puppeteer_core = is_puppeteer_core
end

Instance Method Details

#connect(browser_ws_endpoint: nil, browser_url: nil, transport: nil, ignore_https_errors: nil, default_viewport: nil, slow_mo: nil) ⇒ Puppeteer::Browser

Parameters:

  • browser_ws_endpoint (String) (defaults to: nil)
  • browser_url (String) (defaults to: nil)
  • transport (Puppeteer::WebSocketTransport) (defaults to: nil)
  • ignore_https_errors (Boolean) (defaults to: nil)
  • default_viewport (Puppeteer::Viewport|nil) (defaults to: nil)
  • slow_mo (Integer) (defaults to: nil)

Returns:



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/puppeteer/puppeteer.rb', line 87

def connect(
  browser_ws_endpoint: nil,
  browser_url: nil,
  transport: nil,
  ignore_https_errors: nil,
  default_viewport: nil,
  slow_mo: nil
)
  options = {
    browser_ws_endpoint: browser_ws_endpoint,
    browser_url: browser_url,
    transport: transport,
    ignore_https_errors: ignore_https_errors,
    default_viewport: default_viewport,
    slow_mo: slow_mo,
  }.compact
  browser = launcher.connect(options)
  if block_given?
    begin
      yield(browser)
    ensure
      browser.disconnect
    end
  else
    browser
  end
end

#createBrowserFetcher(options = {}) ⇒ !BrowserFetcher

Parameters:

Returns:



161
162
163
# File 'lib/puppeteer/puppeteer.rb', line 161

def createBrowserFetcher(options = {})
  BrowserFetcher.new(@project_root, options)
end

#default_args(args: nil, user_data_dir: nil, devtools: nil, headless: nil) ⇒ Array<String>

Parameters:

  • args (Array<String>) (defaults to: nil)
  • user_data_dir (String) (defaults to: nil)
  • devtools (Boolean) (defaults to: nil)
  • headless (Boolean) (defaults to: nil)

Returns:

  • (Array<String>)


149
150
151
152
153
154
155
156
157
# File 'lib/puppeteer/puppeteer.rb', line 149

def default_args(args: nil, user_data_dir: nil, devtools: nil, headless: nil)
  options = {
    args: args,
    user_data_dir: user_data_dir,
    devtools: devtools,
    headless: headless,
  }.compact
  launcher.default_args(options)
end

#devicesPuppeteer::Devices

Returns:



135
136
137
# File 'lib/puppeteer/puppeteer.rb', line 135

def devices
  Puppeteer::Devices
end

#executable_pathString

Returns:

  • (String)


116
117
118
# File 'lib/puppeteer/puppeteer.rb', line 116

def executable_path
  launcher.executable_path
end

#launch(product: nil, executable_path: nil, ignore_default_args: nil, handle_SIGINT: nil, handle_SIGTERM: nil, handle_SIGHUP: nil, timeout: nil, dumpio: nil, env: nil, pipe: nil, args: nil, user_data_dir: nil, devtools: nil, headless: nil, ignore_https_errors: nil, default_viewport: nil, slow_mo: nil) ⇒ Puppeteer::Browser

Parameters:

  • product (String) (defaults to: nil)
  • executable_path (String) (defaults to: nil)
  • ignore_default_args (Array<String>|nil) (defaults to: nil)
  • handle_SIGINT (Boolean) (defaults to: nil)
  • handle_SIGTERM (Boolean) (defaults to: nil)
  • handle_SIGHUP (Boolean) (defaults to: nil)
  • timeout (Integer) (defaults to: nil)
  • dumpio (Boolean) (defaults to: nil)
  • env (Hash) (defaults to: nil)
  • pipe (Boolean) (defaults to: nil)
  • args (Array<String>) (defaults to: nil)
  • user_data_dir (String) (defaults to: nil)
  • devtools (Boolean) (defaults to: nil)
  • headless (Boolean) (defaults to: nil)
  • ignore_https_errors (Boolean) (defaults to: nil)
  • default_viewport (Puppeteer::Viewport|nil) (defaults to: nil)
  • slow_mo (Integer) (defaults to: nil)

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/puppeteer/puppeteer.rb', line 29

def launch(
  product: nil,
  executable_path: nil,
  ignore_default_args: nil,
  handle_SIGINT: nil,
  handle_SIGTERM: nil,
  handle_SIGHUP: nil,
  timeout: nil,
  dumpio: nil,
  env: nil,
  pipe: nil,
  args: nil,
  user_data_dir: nil,
  devtools: nil,
  headless: nil,
  ignore_https_errors: nil,
  default_viewport: nil,
  slow_mo: nil
)
  options = {
    executable_path: executable_path,
    ignore_default_args: ignore_default_args,
    handle_SIGINT: handle_SIGINT,
    handle_SIGTERM: handle_SIGTERM,
    handle_SIGHUP: handle_SIGHUP,
    timeout: timeout,
    dumpio: dumpio,
    env: env,
    pipe: pipe,
    args: args,
    user_data_dir: user_data_dir,
    devtools: devtools,
    headless: headless,
    ignore_https_errors: ignore_https_errors,
    default_viewport: default_viewport,
    slow_mo: slow_mo,
  }

  @product_name ||= product
  browser = launcher.launch(options)
  if block_given?
    begin
      yield(browser)
    ensure
      browser.close
    end
  else
    browser
  end
end

#productString

Returns:

  • (String)


130
131
132
# File 'lib/puppeteer/puppeteer.rb', line 130

def product
  launcher.product
end