Last active
April 20, 2023 09:28
-
-
Save willnet/8a446aae5248033c6e9012eb937a11d8 to your computer and use it in GitHub Desktop.
screenshot video sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ferrum' | |
require 'base64' | |
browser = Ferrum::Browser.new(logger: File.open('/tmp/hoge.log', 'w')) | |
Dir.mktmpdir do |dir| | |
browser.on('Page.screencastFrame') do |params, index, total| | |
File.open("#{dir}/#{Time.now.strftime('%Y%m%d%H%M%S%L.jpeg')}", 'w') do |f| | |
f.write(Base64.decode64(params['data'])) | |
end | |
browser.page.command('Page.screencastFrameAck', sessionId: params['sessionId']) | |
rescue | |
warn $! | |
end | |
browser.go_to("https://google.com") | |
browser.page.command('Page.startScreencast', format: 'jpeg', quality: 50, everyNthFramge: 5) | |
input = browser.at_xpath("//textarea[@name='q']") | |
input.focus.type("hoge", :Enter) | |
sleep 1 | |
browser.page.command('Page.stopScreencast') | |
browser.reset | |
browser.quit | |
system("ffmpeg -f image2 -pattern_type glob -framerate 5 -i '#{dir}/*.jpeg' #{Time.now.strftime('%Y%m%d%H%M%S%L')}.mp4") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment