Class: Ferrum::Browser::Process
- Inherits:
-
Object
- Object
- Ferrum::Browser::Process
- Extended by:
- Forwardable
- Defined in:
- lib/ferrum/browser/process.rb,
lib/ferrum/browser/process/killer.rb,
lib/ferrum/browser/process/output.rb,
sig/ferrum/browser/process.rbs,
sig/ferrum/browser/process/killer.rbs,
sig/ferrum/browser/process/output.rbs
Overview
Defined Under Namespace
Modules: Killer Classes: Output
Constant Summary collapse
- HTTP_SCHEMES =
{ "ws" => "http", "wss" => "https" }.freeze
- WS_SCHEMES =
{ "http" => "ws", "https" => "wss" }.freeze
- LOCAL_HOSTS =
%w[0.0.0.0 :: 127.0.0.1 ::1 localhost].freeze
- WS_URL =
%r{DevTools listening on (ws://.*[a-zA-Z0-9-]{36})}
Instance Attribute Summary collapse
-
#command ⇒ Browser::Command?
readonly
Returns the value of attribute command.
-
#host ⇒ String?
readonly
Returns the value of attribute host.
-
#output ⇒ Output
readonly
What the browser process wrote to stdout and stderr, empty for a browser Ferrum didn't launch.
-
#pid ⇒ ::Integer?
readonly
Returns the value of attribute pid.
-
#port ⇒ ::Integer?
readonly
Returns the value of attribute port.
-
#ws_url ⇒ Addressable::URI?, ...
readonly
Returns the value of attribute ws_url.
-
#xvfb ⇒ Browser::Xvfb?
readonly
Returns the value of attribute xvfb.
Class Method Summary collapse
-
.start(*args) ⇒ Process
Builds and starts a new browser process.
Instance Method Summary collapse
-
#initialize(options) ⇒ Process
constructor
A new instance of Process.
-
#inspect ⇒ String
Custom inspection that omits noisy internal command details.
- #path ⇒ String
-
#restart ⇒ void
Stops and starts the browser process again.
-
#start ⇒ void
Spawns the browser process and waits for it to become reachable over CDP.
-
#stop(wait: true, grace: 0) ⇒ Thread?
Kills the browser process (and Xvfb, if running) and removes the user data directory.
Constructor Details
#initialize(options) ⇒ Process
Returns a new instance of Process.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ferrum/browser/process.rb', line 54 def initialize() @pid = @xvfb = @user_data_dir = nil @requested_host = .host @log = .log @output = Output.new(@log) if .ws_url || .url self.ws_url = .ws_url || fetch_ws_url(.url, .process_timeout, .ssl_context) return end @process_timeout = .process_timeout @env = Hash(.env) @user_data_dir = Dir.mktmpdir("ferrum_user_data_dir_") @command = Command.build(, @user_data_dir) end |
Instance Attribute Details
#command ⇒ Browser::Command? (readonly)
Returns the value of attribute command.
46 47 48 |
# File 'lib/ferrum/browser/process.rb', line 46 def command @command end |
#host ⇒ String? (readonly)
Returns the value of attribute host.
46 47 48 |
# File 'lib/ferrum/browser/process.rb', line 46 def host @host end |
#output ⇒ Output (readonly)
What the browser process wrote to stdout and stderr, empty for a browser Ferrum didn't launch.
52 53 54 |
# File 'lib/ferrum/browser/process.rb', line 52 def output @output end |
#pid ⇒ ::Integer? (readonly)
Returns the value of attribute pid.
46 47 48 |
# File 'lib/ferrum/browser/process.rb', line 46 def pid @pid end |
#port ⇒ ::Integer? (readonly)
Returns the value of attribute port.
46 47 48 |
# File 'lib/ferrum/browser/process.rb', line 46 def port @port end |
#ws_url ⇒ Addressable::URI?, ...
Returns the value of attribute ws_url.
46 47 48 |
# File 'lib/ferrum/browser/process.rb', line 46 def ws_url @ws_url end |
#xvfb ⇒ Browser::Xvfb? (readonly)
Returns the value of attribute xvfb.
46 47 48 |
# File 'lib/ferrum/browser/process.rb', line 46 def xvfb @xvfb end |
Class Method Details
.start(*args) ⇒ Process
Builds and starts a new browser process.
42 43 44 |
# File 'lib/ferrum/browser/process.rb', line 42 def self.start(*args) new(*args).tap(&:start) end |
Instance Method Details
#inspect ⇒ String
Custom inspection that omits noisy internal command details.
137 138 139 140 141 142 |
# File 'lib/ferrum/browser/process.rb', line 137 def inspect "#<#{self.class} " \ "@user_data_dir=#{@user_data_dir.inspect} " \ "@command=#<#{@command.class}:#{@command.object_id}> " \ "@ws_url=#{@ws_url.inspect}>" end |
#path ⇒ String
51 |
# File 'sig/ferrum/browser/process.rbs', line 51
def path: () -> String
|
#restart ⇒ void
This method returns an undefined value.
Stops and starts the browser process again.
127 128 129 130 |
# File 'lib/ferrum/browser/process.rb', line 127 def restart stop start end |
#start ⇒ void
This method returns an undefined value.
Spawns the browser process and waits for it to become reachable over CDP.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ferrum/browser/process.rb', line 77 def start # Don't do anything as browser is already running as external process. return if ws_url begin @xvfb = Xvfb.start(@command.) if @command.xvfb? @output = Output.new(@log) @output.pipe { |io| spawn_browser(io) } parse_ws_url @output.follow ensure @output.close unless ws_url end end |
#stop(wait: true, grace: 0) ⇒ Thread?
Kills the browser process (and Xvfb, if running) and removes the user data directory.
116 117 118 119 120 |
# File 'lib/ferrum/browser/process.rb', line 116 def stop(wait: true, grace: 0) return sync_stop(grace) if wait async_stop(grace) end |