Class: Puppeteer::BrowserRunner
- Inherits:
-
Object
- Object
- Puppeteer::BrowserRunner
- Defined in:
- lib/puppeteer/browser_runner.rb
Overview
Defined Under Namespace
Classes: BrowserProcess
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#proc ⇒ Object
readonly
Returns the value of attribute proc.
Instance Method Summary collapse
- #close ⇒ Promise
-
#initialize(executable_path, process_arguments, temp_directory) ⇒ BrowserRunner
constructor
A new instance of BrowserRunner.
- #kill ⇒ Promise
- #setup_connection(use_pipe:, timeout:, slow_mo:, preferred_revision:) ⇒ !Promise<!Connection>
- #start(executable_path: nil, ignore_default_args: nil, handle_SIGINT: nil, handle_SIGTERM: nil, handle_SIGHUP: nil, timeout: nil, dumpio: nil, env: nil, pipe: nil) ⇒ Object
Constructor Details
#initialize(executable_path, process_arguments, temp_directory) ⇒ BrowserRunner
Returns a new instance of BrowserRunner.
10 11 12 13 14 15 16 17 18 |
# File 'lib/puppeteer/browser_runner.rb', line 10 def initialize(executable_path, process_arguments, temp_directory) @executable_path = executable_path @process_arguments = process_arguments @temp_directory = temp_directory @proc = nil @connection = nil @closed = true @listeners = [] end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
20 21 22 |
# File 'lib/puppeteer/browser_runner.rb', line 20 def connection @connection end |
#proc ⇒ Object (readonly)
Returns the value of attribute proc.
20 21 22 |
# File 'lib/puppeteer/browser_runner.rb', line 20 def proc @proc end |
Instance Method Details
#close ⇒ Promise
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/puppeteer/browser_runner.rb', line 108 def close return if @closed if @temp_directory kill elsif @connection begin @connection.('Browser.close') rescue kill end end @process_closing.call end |
#kill ⇒ Promise
125 126 127 128 129 130 131 132 |
# File 'lib/puppeteer/browser_runner.rb', line 125 def kill unless @closed @proc.kill end if @temp_directory FileUtils.rm_rf(@temp_directory) end end |
#setup_connection(use_pipe:, timeout:, slow_mo:, preferred_revision:) ⇒ !Promise<!Connection>
137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/puppeteer/browser_runner.rb', line 137 def setup_connection(use_pipe:, timeout:, slow_mo:, preferred_revision:) if !use_pipe browser_ws_endpoint = wait_for_ws_endpoint(@proc, timeout, preferred_revision) transport = Puppeteer::WebSocketTransport.create(browser_ws_endpoint) @connection = Puppeteer::Connection.new(browser_ws_endpoint, transport, slow_mo) else raise NotImplementedError.new('PipeTransport is not yet implemented') end @connection end |
#start(executable_path: nil, ignore_default_args: nil, handle_SIGINT: nil, handle_SIGTERM: nil, handle_SIGHUP: nil, timeout: nil, dumpio: nil, env: nil, pipe: nil) ⇒ Object
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 |
# File 'lib/puppeteer/browser_runner.rb', line 44 def start( executable_path: nil, ignore_default_args: nil, handle_SIGINT: nil, handle_SIGTERM: nil, handle_SIGHUP: nil, timeout: nil, dumpio: nil, env: nil, pipe: nil ) @launch_options = Puppeteer::Launcher::LaunchOptions.new({ 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, }.compact) @proc = BrowserProcess.new( @launch_options.env, @executable_path, @process_arguments, ) # if (dumpio) { # this.proc.stderr.pipe(process.stderr); # this.proc.stdout.pipe(process.stdout); # } @closed = false @process_closing = -> { @proc.dispose @closed = true if @temp_directory FileUtils.rm_rf(@temp_directory) end } trap(:EXIT) do kill end if @launch_options.handle_SIGINT? trap(:INT) do kill exit 130 end end if @launch_options.handle_SIGTERM? trap(:TERM) do close end end if @launch_options.handle_SIGHUP? trap(:HUP) do close end end end |