Method: Ferrum::Client::WebSocket#on_message

Defined in:
lib/ferrum/client/web_socket.rb

#on_message(event) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ferrum/client/web_socket.rb', line 52

def on_message(event)
  data = safely_parse_json(event.data)
  # If we couldn't parse JSON data for some reason (parse error or deeply nested object) we
  # don't push response to @messages. Worse that could happen we raise timeout error due to command didn't return
  # anything or skip the background notification, but at least we don't crash the thread that crashes the main
  # thread and the application.
  @messages.push(data) if data

  output = event.data
  if SKIP_LOGGING_SCREENSHOTS && @screenshot_commands[data&.dig("id")]
    @screenshot_commands.delete(data&.dig("id"))
    output.sub!(/{"data":"[^"]*"}/, %("Set FERRUM_LOGGING_SCREENSHOTS=true to see screenshots in Base64"))
  end

  @logger&.puts("#{Utils::ElapsedTime.elapsed_time} #{output}\n")
end