Class: Capybara::Cuprite::Browser::Process
- Inherits:
-
Object
- Object
- Capybara::Cuprite::Browser::Process
- Defined in:
- lib/capybara/cuprite/browser/process.rb
Constant Summary collapse
- KILL_TIMEOUT =
2
- BROWSER_PATH =
ENV["BROWSER_PATH"]
- BROWSER_HOST =
"127.0.0.1"
- BROWSER_PORT =
"0"
- DEFAULT_OPTIONS =
{ "headless" => nil, "disable-gpu" => nil, "hide-scrollbars" => nil, "mute-audio" => nil, "enable-automation" => nil, "disable-web-security" => nil, "disable-session-crashed-bubble" => nil, "disable-breakpad" => nil, "disable-sync" => nil, "no-first-run" => nil, "use-mock-keychain" => nil, "keep-alive-for-test" => nil, "disable-popup-blocking" => nil, "disable-extensions" => nil, "disable-hang-monitor" => nil, "disable-features" => "site-per-process,TranslateUI", "disable-translate" => nil, "disable-background-networking" => nil, "enable-features" => "NetworkService,NetworkServiceInProcess", "disable-background-timer-throttling" => nil, "disable-backgrounding-occluded-windows" => nil, "disable-client-side-phishing-detection" => nil, "disable-default-apps" => nil, "disable-dev-shm-usage" => nil, "disable-ipc-flooding-protection" => nil, "disable-prompt-on-repost" => nil, "disable-renderer-backgrounding" => nil, "force-color-profile" => "srgb", "metrics-recording-only" => nil, "safebrowsing-disable-auto-update" => nil, "password-store" => "basic", # Note: --no-sandbox is not needed if you properly setup a user in the container. # https://github.com/ebidel/lighthouse-ci/blob/master/builder/Dockerfile#L35-L40 # "no-sandbox" => nil, }.freeze
Instance Attribute Summary collapse
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#ws_url ⇒ Object
readonly
Returns the value of attribute ws_url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ Process
constructor
A new instance of Process.
- #restart ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options) ⇒ Process
Returns a new instance of Process.
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 |
# File 'lib/capybara/cuprite/browser/process.rb', line 76 def initialize() @options = {} detect_browser_path() # Doesn't work on MacOS, so we need to set it by CDP as well @options.merge!("window-size" => [:window_size].join(",")) port = .fetch(:port, BROWSER_PORT) @options.merge!("remote-debugging-port" => port) host = .fetch(:host, BROWSER_HOST) @options.merge!("remote-debugging-address" => host) @options.merge!("user-data-dir" => Dir.mktmpdir) @options = DEFAULT_OPTIONS.merge(@options) unless .fetch(:headless, true) @options.delete("headless") @options.delete("disable-gpu") end @options.merge!(.fetch(:browser_options, {})) @logger = .fetch(:logger, nil) end |
Instance Attribute Details
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
49 50 51 |
# File 'lib/capybara/cuprite/browser/process.rb', line 49 def cmd @cmd end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
49 50 51 |
# File 'lib/capybara/cuprite/browser/process.rb', line 49 def host @host end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
49 50 51 |
# File 'lib/capybara/cuprite/browser/process.rb', line 49 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
49 50 51 |
# File 'lib/capybara/cuprite/browser/process.rb', line 49 def path @path end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
49 50 51 |
# File 'lib/capybara/cuprite/browser/process.rb', line 49 def pid @pid end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
49 50 51 |
# File 'lib/capybara/cuprite/browser/process.rb', line 49 def port @port end |
#ws_url ⇒ Object (readonly)
Returns the value of attribute ws_url.
49 50 51 |
# File 'lib/capybara/cuprite/browser/process.rb', line 49 def ws_url @ws_url end |
Class Method Details
.process_killer(pid) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/capybara/cuprite/browser/process.rb', line 55 def self.process_killer(pid) proc do begin if Capybara::Cuprite.windows? ::Process.kill("KILL", pid) else ::Process.kill("USR1", pid) start = Time.now while ::Process.wait(pid, ::Process::WNOHANG).nil? sleep 0.05 next unless (Time.now - start) > KILL_TIMEOUT ::Process.kill("KILL", pid) ::Process.wait(pid) break end end rescue Errno::ESRCH, Errno::ECHILD end end end |
.start(*args) ⇒ Object
51 52 53 |
# File 'lib/capybara/cuprite/browser/process.rb', line 51 def self.start(*args) new(*args).tap(&:start) end |
Instance Method Details
#restart ⇒ Object
129 130 131 132 |
# File 'lib/capybara/cuprite/browser/process.rb', line 129 def restart stop start end |
#start ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/capybara/cuprite/browser/process.rb', line 104 def start read_io, write_io = IO.pipe = { in: File::NULL } [:pgroup] = true unless Capybara::Cuprite.windows? if Capybara::Cuprite.mri? [:out] = [:err] = write_io end redirect_stdout(write_io) do @cmd = [@path] + @options.map { |k, v| v.nil? ? "--#{k}" : "--#{k}=#{v}" } @pid = ::Process.spawn(*@cmd, ) ObjectSpace.define_finalizer(self, self.class.process_killer(@pid)) end parse_ws_url(read_io) ensure close_io(read_io, write_io) end |
#stop ⇒ Object
123 124 125 126 127 |
# File 'lib/capybara/cuprite/browser/process.rb', line 123 def stop return unless @pid kill ObjectSpace.undefine_finalizer(self) end |