Screencast
start_screencast(**options) { |data, metadata, session_id| ... }
Starts sending frames to record screencast to the given block.
-
options
Hash- :format
Symbol:jpeg|:pngThe format the image should be returned in. - :quality
IntegerThe image quality. Note: 0-100 works for JPEG only. - :max_width
IntegerMaximum screencast frame width. - :max_height
IntegerMaximum screencast frame height. - :every_nth_frame
IntegerSend every n-th frame.
- :format
-
Block inputs:
- data
StringBase64-encoded compressed image. - metadata
HashScreencast frame metadata.- "offsetTop"
IntegerTop offset in DIP. - "pageScaleFactor"
IntegerPage scale factor. - "deviceWidth"
IntegerDevice screen width in DIP. - "deviceHeight"
IntegerDevice screen height in DIP. - "scrollOffsetX"
IntegerPosition of horizontal scroll in CSS pixels. - "scrollOffsetY"
IntegerPosition of vertical scroll in CSS pixels. - "timestamp"
Float(optional) Frame swap timestamp in seconds since Unix epoch.
- "offsetTop"
- session_id
IntegerFrame number.
- data
require "base64"
page.go_to("https://apple.com/ipad")
page.start_screencast(format: :jpeg, quality: 75) do |data, metadata|
timestamp = (metadata["timestamp"] * 1000).to_i
File.binwrite("image_#{timestamp}.jpg", Base64.decode64(data))
end
sleep 10
page.stop_screencast
📝 NOTE
Chrome only sends new frames while page content is changing. For example, if there is an animation or a video on the page, Chrome sends frames at the rate requested. On the other hand, if the page is nothing but a wall of static text, Chrome sends frames while the page renders. Once Chrome has finished rendering the page, it sends no more frames until something changes (e.g., navigating to another location).
stop_screencast
Stops sending frames.