I make a small iPhone puzzle game, Clover Case. The app is a thin native shell around a WebView, and the WebView shows one HTML page with a Three.js board. That turned out to be handy for marketing: I can record real gameplay clips on my Windows PC without a phone, a screen recorder or a simulator. Here is the setup in about 25 lines of Python.
The idea
- Open the game's own
index.htmlin headless Chromium with Playwright. - Let the game play itself (it has a built-in autoplay mode that I use for testing; a URL hash switches it on).
- Let Playwright record the page as a video.
- Stop when the game state says the board is full, then convert to a vertical 1080x1920 MP4 with ffmpeg.
Because it's the same file that ships inside the app, the clip shows exactly what players see. No mock-up, no website build.
Getting WebGL to render headless
Headless Chromium on a machine without a usable GPU often gives you a black canvas. Forcing ANGLE onto SwiftShader (software rendering) fixed it for me:
b = p.chromium.launch(headless=True, args=[ "--use-gl=angle", "--use-angle=swiftshader", "--enable-unsafe-swiftshader", "--ignore-gpu-blocklist", "--no-sandbox"]) It's slower than a real GPU, but a 20-second puzzle doesn't need 60 fps of real time. Playwright records whatever the page draws.
Recording a portrait video
Set the viewport and the video size to the same portrait size, so you don't get letterboxing:
W, H = 1080, 1920 ctx = b.new_context(viewport={"width": W, "height": H}, record_video_dir="tmp", record_video_size={"width": W, "height": H}) ctx.add_init_script("try{localStorage.setItem('cc_tut','1')}catch(e){}") # skip the tutorial overlay pg = ctx.new_page() pg.goto(game_url + "#autoplay-diff=hard-level=12", wait_until="domcontentloaded") add_init_script runs before the page's own scripts, so it's the right place to pre-set flags like "tutorial already seen".
Knowing when to stop
Don't wait a fixed number of seconds. Ask the game:
end = time.time() + 40 while time.time() < end: pg.wait_for_timeout(1000) if pg.evaluate("() => typeof board!=='undefined' && board && !board.includes(null)"): pg.wait_for_timeout(2200) # keep the win animation break ctx.close() # the video file is only finished after the context closes The script prints whether the board actually got full. If it says no, I don't use the clip.
Converting with ffmpeg
Playwright writes WebM with a short blank start. Trim it, set a steady frame rate, and encode H.264 with +faststart so the upload sites can process it straight away:
ffmpeg -y -ss 1.2 -i in.webm -vf "scale=1080:1920,fps=30,format=yuv420p" \ -an -c:v libx264 -crf 20 -movflags +faststart out.mp4 A few extras that helped:
- Join clips: write the files into a list and use
ffmpeg -f concat -safe 0 -i list.txt -c copy joined.mp4(works when all clips share the same encode settings). - End caption:
drawtextwithbox=1:boxcolor=black@0.6andenable='gte(t,DUR-3)'for the last three seconds. - Long clips:
setpts=PTS/2doubles the speed. If you do that, say "2x speed" in the title so nobody feels misled. - Check before posting:
ffmpeg -i out.mp4 -vf "fps=1/2,scale=270:-1,tile=4x3" sheet.pnggives a contact sheet, so I can spot a black or frozen clip in one look.
Drag-based games
My second game, Noodle Pop, needs real drags instead of autoplay. Playwright's page.mouse.down(), move(x, y, steps=20) and up() produce pointer events that the game can't tell apart from a mouse, and the steps value makes the drag visible in the recording instead of a teleport.
Why bother
For a solo developer with no ad budget, short real-gameplay clips are one of the few free channels I can use on YouTube Shorts and Tumblr. With this script a new clip takes a minute, and every clip is honest footage of the shipped game.
If you want to see the result: a Clover Case gameplay Short and a Noodle Pop one. Both games are free on iPhone: Clover Case and Noodle Pop. They're Kanoodle-style puzzles; Kanoodle is a trademark of Educational Insights and my games aren't affiliated with it.
Disclosure: the game art is AI-generated, and the game code and this post were written with an AI coding assistant.
