on Ubuntu 22
If you are looking to make a screen capture of Firefox in an automated manner, you can use xvfb to do so.
On X11, Xvfb is a tool you can use to start a virtual framebuffer. Within a new display you create you can run applications, and ultimately use ffmpeg to record that particular display.
sudo xvfb-run --listen-tcp --server-num 99 -s "-nocursor -ac -screen 0 1280x720x24" firefox -kiosk "https://lobste.rs"
The above will:
99
1280x720
https://lobste.rs
We can then record display 99
with ffmpeg, producing test.mp4
:
ffmpeg -y -f pulse -i 0 -framerate 30 -f x11grab -video_size 1280x720 -draw_mouse 0 -i :2 -pix_fmt yuv420p -vcodec libx264 -crf 24 -acodec aac -b:a 128k -movflags +faststart test.mp4
Before recording, it is often a good idea to move the window to position(x,y) 0,0
to
make sure Firefox is properly in-view. We can use xdotool
for this:
wid=`DISPLAY=":99" xdotool search --onlyvisible firefox`
echo "move $wid"
DISPLAY=":99" xdotool windowmove "$wid" 0 0
echo "size $wid"
DISPLAY=":99" xdotool windowsize "$wid" 1280 720
That's it, you now have a video of the website you opened. The benefit here is that you can spawn a number of display servers, all recording at the same time.
One final tip: To prevent popups, advertisements, and other shenanigans that may mess up your recording, it is a good idea to prepare a Firefox profile with pre-installed extensions such as:
To go even further, you may also install greasemonkey. This is useful in case you want to programmatically change the behavior of the website you are recording like changing CSS, clicking buttons, and making a video go fullscreen.