Class: Camoufox::SyncAPI::NodeRunner::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/camoufox/sync_api.rb

Instance Method Summary collapse

Constructor Details

#initialize(launch_options) ⇒ Session

Returns a new instance of Session.



114
115
116
117
118
119
120
# File 'lib/camoufox/sync_api.rb', line 114

def initialize(launch_options)
  @launch_options = launch_options
  @command_id = 0
  @closed = false
  spawn_session
  wait_for_ready
end

Instance Method Details

#closeObject



135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/camoufox/sync_api.rb', line 135

def close
  return if @closed

  begin
    request('close')
  rescue NodeExecutionFailed
    # swallow shutdown errors
  ensure
    @closed = true
    cleanup
  end
end

#request(action, params = {}) ⇒ Object

Raises:



122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/camoufox/sync_api.rb', line 122

def request(action, params = {})
  raise Camoufox::Error, "Page session is closed" if @closed

  @command_id += 1
  payload = {
    'id' => @command_id,
    'action' => action,
    'params' => params,
  }
  write_message(payload)
  handle_response(@command_id)
end