Class: Puppeteer::Puppeteer
- Inherits:
-
Object
- Object
- Puppeteer::Puppeteer
- Defined in:
- lib/puppeteer/puppeteer.rb
Overview
rbs_inline: enabled
Defined Under Namespace
Classes: NoViewport
Instance Method Summary collapse
- #clear_custom_query_handlers ⇒ Object
- #connect(browser_ws_endpoint: nil, browser_url: nil, transport: nil, ignore_https_errors: nil, network_enabled: true, issues_enabled: true, block_list: nil, default_viewport: nil, slow_mo: nil, protocol_timeout: nil, &block) ⇒ Object
- #custom_query_handler_names ⇒ Object
- #default_args(args: nil, user_data_dir: nil, devtools: nil, headless: nil) ⇒ Object
- #devices ⇒ Object
- #executable_path(channel: nil) ⇒ Object
-
#initialize(project_root:, preferred_revision:, is_puppeteer_core:) ⇒ Puppeteer
constructor
A new instance of Puppeteer.
- #launch(product: nil, channel: 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, debugging_port: nil, headless: nil, ignore_https_errors: nil, network_enabled: true, issues_enabled: true, block_list: nil, enable_extensions: false, default_viewport: NoViewport.new, slow_mo: nil, protocol_timeout: nil, wait_for_initial_page: nil, &block) ⇒ Object
- #network_conditions ⇒ Object
- #product ⇒ Object
- #register_custom_query_handler(name:, query_one: nil, query_all: nil) ⇒ Object
- #unregister_custom_query_handler(name:) ⇒ Object
- #with_custom_query_handler(name:, query_one: nil, query_all: nil, &block) ⇒ Object
Constructor Details
#initialize(project_root:, preferred_revision:, is_puppeteer_core:) ⇒ Puppeteer
Returns a new instance of Puppeteer.
8 9 10 11 12 |
# File 'lib/puppeteer/puppeteer.rb', line 8 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
#clear_custom_query_handlers ⇒ Object
294 295 296 |
# File 'lib/puppeteer/puppeteer.rb', line 294 def clear_custom_query_handlers query_handler_manager.clear_custom_query_handlers end |
#connect(browser_ws_endpoint: nil, browser_url: nil, transport: nil, ignore_https_errors: nil, network_enabled: true, issues_enabled: true, block_list: nil, default_viewport: nil, slow_mo: nil, protocol_timeout: nil, &block) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/puppeteer/puppeteer.rb', line 152 def connect( browser_ws_endpoint: nil, browser_url: nil, transport: nil, ignore_https_errors: nil, network_enabled: true, issues_enabled: true, block_list: nil, default_viewport: nil, slow_mo: nil, protocol_timeout: nil, &block ) = { browser_ws_endpoint: browser_ws_endpoint, browser_url: browser_url, transport: transport, ignore_https_errors: ignore_https_errors, network_enabled: network_enabled, issues_enabled: issues_enabled, block_list: block_list, default_viewport: , slow_mo: slow_mo, protocol_timeout: protocol_timeout, }.compact if async_context? browser = Puppeteer::BrowserConnector.new().connect_to_browser if block begin block.call(browser) ensure browser.disconnect end else browser end else runner = Puppeteer::ReactorRunner.new begin browser = runner.sync { Puppeteer::BrowserConnector.new().connect_to_browser } rescue StandardError runner.close raise end proxy = Puppeteer::ReactorRunner::Proxy.new(runner, browser, owns_runner: true) if block begin block.call(proxy) ensure proxy.disconnect end else proxy end end end |
#custom_query_handler_names ⇒ Object
299 300 301 |
# File 'lib/puppeteer/puppeteer.rb', line 299 def custom_query_handler_names query_handler_manager.custom_query_handler_names end |
#default_args(args: nil, user_data_dir: nil, devtools: nil, headless: nil) ⇒ Object
322 323 324 325 326 327 328 329 330 |
# File 'lib/puppeteer/puppeteer.rb', line 322 def default_args(args: nil, user_data_dir: nil, devtools: nil, headless: nil) = { args: args, user_data_dir: user_data_dir, devtools: devtools, headless: headless, }.compact launcher.default_args() end |
#devices ⇒ Object
308 309 310 |
# File 'lib/puppeteer/puppeteer.rb', line 308 def devices Puppeteer::Devices end |
#executable_path(channel: nil) ⇒ Object
211 212 213 |
# File 'lib/puppeteer/puppeteer.rb', line 211 def executable_path(channel: nil) launcher.executable_path(channel: channel) end |
#launch(product: nil, channel: 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, debugging_port: nil, headless: nil, ignore_https_errors: nil, network_enabled: true, issues_enabled: true, block_list: nil, enable_extensions: false, default_viewport: NoViewport.new, slow_mo: nil, protocol_timeout: nil, wait_for_initial_page: nil, &block) ⇒ Object
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 79 80 81 82 83 84 85 86 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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/puppeteer/puppeteer.rb', line 43 def launch( product: nil, channel: 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, debugging_port: nil, headless: nil, ignore_https_errors: nil, network_enabled: true, issues_enabled: true, block_list: nil, enable_extensions: false, default_viewport: NoViewport.new, slow_mo: nil, protocol_timeout: nil, wait_for_initial_page: nil, &block ) product = product.to_s if product if product && product != 'chrome' raise ArgumentError.new("Unsupported product: #{product}. Only 'chrome' is supported.") end = { channel: channel&.to_s, 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, debugging_port: debugging_port, headless: headless, ignore_https_errors: ignore_https_errors, network_enabled: network_enabled, issues_enabled: issues_enabled, block_list: block_list, enable_extensions: enable_extensions, default_viewport: , slow_mo: slow_mo, protocol_timeout: protocol_timeout, wait_for_initial_page: wait_for_initial_page, } if .is_a?(NoViewport) .delete(:default_viewport) end .delete(:wait_for_initial_page) if wait_for_initial_page.nil? @product_name = product if async_context? browser = launcher.launch() if block begin block.call(browser) ensure browser.close end else browser end else runner = Puppeteer::ReactorRunner.new begin browser = runner.sync { launcher.launch() } rescue StandardError runner.close raise end proxy = Puppeteer::ReactorRunner::Proxy.new(runner, browser, owns_runner: true) if block begin block.call(proxy) ensure proxy.close end else proxy end end end |
#network_conditions ⇒ Object
313 314 315 |
# File 'lib/puppeteer/puppeteer.rb', line 313 def network_conditions Puppeteer::NetworkConditions end |
#product ⇒ Object
225 226 227 |
# File 'lib/puppeteer/puppeteer.rb', line 225 def product launcher.product end |
#register_custom_query_handler(name:, query_one: nil, query_all: nil) ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/puppeteer/puppeteer.rb', line 240 def register_custom_query_handler(name:, query_one: nil, query_all: nil) unless name =~ /\A[a-zA-Z]+\z/ raise ArgumentError.new("Custom query handler names may only contain [a-zA-Z]") end if query_one.nil? && query_all.nil? raise ArgumentError.new('At least one query method must be implemented.') end handler = Puppeteer::CustomQueryHandler.new(query_one: query_one, query_all: query_all) handler_name = name.to_sym if query_handler_manager.query_handlers.key?(handler_name) raise ArgumentError.new("A query handler named #{name} already exists") end query_handler_manager.query_handlers[handler_name] = handler end |
#unregister_custom_query_handler(name:) ⇒ Object
289 290 291 |
# File 'lib/puppeteer/puppeteer.rb', line 289 def unregister_custom_query_handler(name:) query_handler_manager.unregister_custom_query_handler(name) end |
#with_custom_query_handler(name:, query_one: nil, query_all: nil, &block) ⇒ Object
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/puppeteer/puppeteer.rb', line 262 def with_custom_query_handler(name:, query_one: nil, query_all: nil, &block) unless name =~ /\A[a-zA-Z]+\z/ raise ArgumentError.new("Custom query handler names may only contain [a-zA-Z]") end if query_one.nil? && query_all.nil? raise ArgumentError.new('At least one query method must be implemented.') end handler_name = name.to_sym handler = Puppeteer::CustomQueryHandler.new(query_one: query_one, query_all: query_all) original = query_handler_manager.query_handlers.delete(handler_name) query_handler_manager.query_handlers[handler_name] = handler begin block.call ensure if original query_handler_manager.query_handlers[handler_name] = original else query_handler_manager.query_handlers.delete(handler_name) end end end |