@@ -8,6 +8,7 @@ module Ferrum
8
8
class Browser
9
9
class WebSocket
10
10
WEBSOCKET_BUG_SLEEP = 0.01
11
+ SKIP_LOGGING_SCREENSHOTS = !ENV [ "FERRUM_LOGGING_SCREENSHOTS" ]
11
12
12
13
attr_reader :url , :messages
13
14
@@ -20,6 +21,10 @@ def initialize(url, max_receive_size, logger)
20
21
@driver = ::WebSocket ::Driver . client ( self , max_length : max_receive_size )
21
22
@messages = Queue . new
22
23
24
+ if SKIP_LOGGING_SCREENSHOTS
25
+ @screenshot_commands = Concurrent ::Hash . new
26
+ end
27
+
23
28
@driver . on ( :open , &method ( :on_open ) )
24
29
@driver . on ( :message , &method ( :on_message ) )
25
30
@driver . on ( :close , &method ( :on_close ) )
@@ -50,7 +55,14 @@ def on_open(_event)
50
55
def on_message ( event )
51
56
data = JSON . parse ( event . data )
52
57
@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 " )
54
66
end
55
67
56
68
def on_close ( _event )
@@ -59,6 +71,10 @@ def on_close(_event)
59
71
end
60
72
61
73
def send_message ( data )
74
+ if SKIP_LOGGING_SCREENSHOTS
75
+ @screenshot_commands [ data [ :id ] ] = true
76
+ end
77
+
62
78
json = data . to_json
63
79
@driver . text ( json )
64
80
@logger &.puts ( "\n \n ▶ #{ Ferrum . elapsed_time } #{ json } " )
0 commit comments