Class: Puppeteer::BrowserRunner
- Inherits:
- 
      Object
      
        - Object
- Puppeteer::BrowserRunner
 
- Defined in:
- lib/puppeteer/browser_runner.rb
Overview
Defined Under Namespace
Classes: BrowserProcess, LaunchError
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 | # 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 end | 
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
| 19 20 21 | # File 'lib/puppeteer/browser_runner.rb', line 19 def connection @connection end | 
#proc ⇒ Object (readonly)
Returns the value of attribute proc.
| 19 20 21 | # File 'lib/puppeteer/browser_runner.rb', line 19 def proc @proc end | 
Instance Method Details
#close ⇒ Promise
| 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | # File 'lib/puppeteer/browser_runner.rb', line 122 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
| 139 140 141 142 143 144 145 146 | # File 'lib/puppeteer/browser_runner.rb', line 139 def kill if @temp_directory FileUtils.rm_rf(@temp_directory) end unless @closed @proc.kill end end | 
#setup_connection(use_pipe:, timeout:, slow_mo:, preferred_revision:) ⇒ !Promise<!Connection>
| 151 152 153 154 155 156 157 158 159 160 161 | # File 'lib/puppeteer/browser_runner.rb', line 151 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
| 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 | # File 'lib/puppeteer/browser_runner.rb', line 58 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 |