@@ -27,7 +27,7 @@ module Screenshot
27
27
def screenshot ( **opts )
28
28
path , encoding = common_options ( **opts )
29
29
options = screenshot_options ( path , **opts )
30
- data = capture_screenshot ( options , opts [ :full ] )
30
+ data = capture_screenshot ( options , opts [ :full ] , opts [ :background_rgba_color ] )
31
31
return data if encoding == :base64
32
32
33
33
bin = Base64 . decode64 ( data )
@@ -143,9 +143,11 @@ def to_camel_case(option)
143
143
option . to_s . gsub ( /(?:_|(\/ ))([a-z\d ]*)/ ) { "#{ $1} #{ $2. capitalize } " } . to_sym
144
144
end
145
145
146
- def capture_screenshot ( options , full )
146
+ def capture_screenshot ( options , full , background_rgba_color )
147
147
maybe_resize_fullscreen ( full ) do
148
- command ( "Page.captureScreenshot" , **options )
148
+ with_background_color ( background_rgba_color ) do
149
+ command ( "Page.captureScreenshot" , **options )
150
+ end
149
151
end . fetch ( "data" )
150
152
end
151
153
@@ -159,6 +161,17 @@ def maybe_resize_fullscreen(full)
159
161
ensure
160
162
resize ( width : width , height : height ) if full
161
163
end
164
+
165
+ def with_background_color ( background_rgba_color )
166
+ if background_rgba_color
167
+ r , g , b , a = background_rgba_color
168
+ command ( 'Emulation.setDefaultBackgroundColorOverride' , color : { r : r , g : g , b : b , a : a } )
169
+ end
170
+
171
+ yield
172
+ ensure
173
+ command ( 'Emulation.setDefaultBackgroundColorOverride' ) if background_rgba_color
174
+ end
162
175
end
163
176
end
164
177
end
0 commit comments