Headless rendering functional, how to take screenshot?

I’m headlessly rendering a scene with Threejs + node and am currently taking screenshots via a command line program that opens a browser, loads the pre-computed scene (loads an array of shapes jsons from a DB), moves the camera to the correct position, takes a screenshot, automatically crops/saves the picture, and then closes the browser.

I’d like to be able to do this completely headlessly: no browser whatsoever. No gui necessary. Is this possible, and if so, how?

(Sorry this is not strictly a threejs question, but I figure folks here might have had this question previously.)

The E2E tests of three.js do this with Puppeteer: GitHub - puppeteer/puppeteer: Headless Chrome Node.js API

The project uses it to make screenshots of almost all official examples. When something in the library is changed, a backend task generates new screenshots and compares them with the predefined ones. If the rendering is broken for one or more examples, the entire E2E test fails and we know something is going wrong.