Skip to content

Commit cc353df

Browse files
committed
Don't show screenshots in Base64 in the output when debug mode is on.
1 parent 377b397 commit cc353df

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lib/ferrum/browser/web_socket.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Ferrum
88
class Browser
99
class WebSocket
1010
WEBSOCKET_BUG_SLEEP = 0.01
11+
SKIP_LOGGING_SCREENSHOTS = !ENV["FERRUM_LOGGING_SCREENSHOTS"]
1112

1213
attr_reader :url, :messages
1314

@@ -20,6 +21,10 @@ def initialize(url, max_receive_size, logger)
2021
@driver = ::WebSocket::Driver.client(self, max_length: max_receive_size)
2122
@messages = Queue.new
2223

24+
if SKIP_LOGGING_SCREENSHOTS
25+
@screenshot_commands = Concurrent::Hash.new
26+
end
27+
2328
@driver.on(:open, &method(:on_open))
2429
@driver.on(:message, &method(:on_message))
2530
@driver.on(:close, &method(:on_close))
@@ -50,7 +55,14 @@ def on_open(_event)
5055
def on_message(event)
5156
data = JSON.parse(event.data)
5257
@messages.push(data)
53-
@logger&.puts(" ◀ #{Ferrum.elapsed_time} #{event.data}\n")
58+
59+
output = event.data
60+
if SKIP_LOGGING_SCREENSHOTS && @screenshot_commands[data["id"]]
61+
@screenshot_commands.delete(data["id"])
62+
output.sub!(/{"data":"(.*)"}/, %("Set FERRUM_LOGGING_SCREENSHOTS=true to see screenshots in Base64"))
63+
end
64+
65+
@logger&.puts(" ◀ #{Ferrum.elapsed_time} #{output}\n")
5466
end
5567

5668
def on_close(_event)
@@ -59,6 +71,10 @@ def on_close(_event)
5971
end
6072

6173
def send_message(data)
74+
if SKIP_LOGGING_SCREENSHOTS
75+
@screenshot_commands[data[:id]] = true
76+
end
77+
6278
json = data.to_json
6379
@driver.text(json)
6480
@logger&.puts("\n\n#{Ferrum.elapsed_time} #{json}")

0 commit comments

Comments
 (0)