SkillAgentSearch skills...

Timesnap

Node.js program that takes screenshots at smooth intervals of web pages with JavaScript animations

Install / Use

/learn @tungs/Timesnap
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

timesnap

timesnap is a Node.js program that records screenshots of web pages that use JavaScript animations. It uses timeweb and puppeteer to open a web page, overwrite its time-handling functions, and record snapshots at virtual times. For some web pages, this allows frames to be recorded slower than real time, while appearing smooth and consistent when recreated into a video.

You can use timesnap from the command line or as a Node.js library. It requires Node v8.9.0 or higher and npm.

To record screenshots and compile them into a video using only one command, see timecut. For using virtual time in browser, see timeweb.

<a name="limitations" href="#limitations">#</a> timeweb and timesnap Limitations

timeweb (and timesnap by extension) only overwrites JavaScript functions and video playback, so pages where changes occur via other means (e.g. through transitions/animations from CSS rules) will likely not render as intended.

Read Me Contents

<a name="from-cli" href="#from-cli">#</a> From the Command Line

<a name="cli-global-install" href="#cli-global-install">#</a> Global Install and Use

To install:

Due to an issue in puppeteer with permissions, timesnap is not supported for global installation for root. You can configure npm to install global packages for a specific user by following this guide: https://docs.npmjs.com/getting-started/fixing-npm-permissions#option-two-change-npms-default-directory

After configuring, run:

npm install -g timesnap

To use:

timesnap "url" [options]

<a name="cli-local-install" href="#cli-local-install">#</a> Local Install and Use

To install:

cd /path/to/installation/directory
npm install timesnap

To use:

node /path/to/installation/directory/node_modules/timesnap/cli.js "url" [options]

Alternatively:

To install:

cd /path/to/installation/directory
git clone https://github.com/tungs/timesnap.git
cd timesnap
npm install

To use:

node /path/to/installation/directory/timesnap/cli.js "url" [options]

<a name="cli-url-use" href="#cli-url-use">#</a> Command Line url

The url can be a web url (e.g. https://github.com) or a file path, with relative paths resolving in the current working directory. If no url is specified, defaults to index.html. Remember to enclose urls that contain special characters (like # and &) with quotes.

<a name="cli-examples" href="#cli-examples">#</a> Command Line Examples

<a name="cli-example-default" href="#cli-example-default">#</a> Default behavior:

timesnap

Opens index.html in the current working directory, sets the viewport to 800x600, captures at 60 frames per second for 5 virtual seconds, and saves the frames to 001.png to 300.png in the current working directory. The defaults may change in the future, so for long-term scripting, it's a good idea to explicitly pass these options, like in the following example.

<a name="cli-example-viewport-fps-duration-output" href="#cli-example-viewport-fps-duration-output">#</a> Setting viewport size, frames per second, duration, and output pattern:

timesnap index.html --viewport="800,600" --fps=60 --duration=5 --output-pattern="%03d.png"

Equivalent to the current default timesnap invocation, but with explicit options. Opens index.html in the current working directory, sets the viewport to 800x600, captures at 60 frames per second for 5 virtual seconds, and saves the frames to 001.png to 300.png in the current working directory.

<a name="cli-example-selector" href="#cli-example-selector">#</a> Using a selector:

timesnap drawing.html -S "canvas,svg" --output-pattern="frames/%03d.png"

Opens drawing.html in the current working directory, crops each frame to the bounding box of the first canvas or svg element, and captures frames using default settings (5 seconds @ 60fps), saving to frames/001.png... frames/300.png in the current working directory, making the directory frames if needed.

<a name="cli-example-offsets" href="#cli-example-offsets">#</a> Using offsets:

timesnap "https://tungs.github.io/amuse/truchet-tiles/#autoplay=true&switchStyle=random" \
  -S "#container" \
  --left=20 --top=40 --right=6 --bottom=30 \
  --duration=20 --output-directory=frames

Opens https://tungs.github.io/amuse/truchet-tiles/#autoplay=true&switchStyle=random (note the quotes in the url are necessary because of the # and &). Crops each frame to the #container element, with an additional crop of 20px, 40px, 6px, and 30px for the left, top, right, and bottom, respectively. Captures frames for 20 virtual seconds at 60fps to frames/0001.png... frames/1200.png in the current working directory, making the directory frames if needed.

<a name="cli-example-piping" href="#cli-example-piping">#</a> Piping:

timesnap https://breathejs.org/examples/Drawing-US-Counties.html \
  -V "1920,1080" -S "#draw-canvas" --fps=60 --duration=10 \
  --round-to-even-width --round-to-even-height \
  --output-stdout | ffmpeg -framerate 60 -i pipe:0 -y -pix_fmt yuv420p video.mp4

Opens https://breathejs.org/examples/Drawing-US-Counties.html, sets the viewport size to 1920x1080, crops each frame to the bounding box of #draw-canvas, records at 60 frames per second for ten virtual seconds, and pipes the output to ffmpeg, which reads in the data from stdin, encodes the frames using pixel format yuv420p, and saves the result as video.mp4 in the current working directory. It does not save individual frames to disk. It uses the --round-to-even-width and --round-to-even-height options to ensure the dimensions of the frames are even numbers, which ffmpeg requires for certain encodings.

<a name="cli-options" href="#cli-options">#</a> Command Line options

  • <a name="cli-options-output-directory" href="#cli-options-output-directory">#</a> Output Directory: -o, --output-directory directory
    • Saves images to a directory (default ./).
  • <a name="cli-options-output-pattern" href="#cli-options-output-pattern">#</a> Output Pattern: -O, --output-pattern pattern
    • Sets each file name according to a printf-style pattern (e.g. image-%03d.png).
  • <a name="cli-options-fps" href="#cli-options-fps">#</a> Frame Rate: -R, --fps frame rate
    • Frame rate (in frames per virtual second) of capture (default: 60).
  • <a name="cli-options-duration" href="#cli-options-duration">#</a> Duration: -d, --duration seconds
    • Duration of capture, in seconds (default: 5).
  • <a name="cli-options-frames" href="#cli-options-frames">#</a> Frames: --frames count
    • Number of frames to capture.
  • <a name="cli-options-selector" href="#cli-options-selector">#</a> Selector: -S, --selector "selector"
    • Crops each frame to the bounding box of the first item found by the [CSS selector][CSS selector].
  • <a name="cli-options-viewport" href="#cli-options-viewport">#</a> Viewport: -V, --viewport dimensions,otherOptions
    • Viewport dimensions, in pixels, followed by optional keys. For example, 800 (for width), or "800,600" (for width and height), or "800,600,deviceScaleFactor=2" for (width, height, and deviceScaleFactor). When running in Windows, quotes may be necessary for parsing commas. For a list of optional keys, see config.viewport.
  • <a name="cli-options-canvas-capture-mode" href="#cli-options-canvas-capture-mode">#</a> Canvas Capture Mode: --canvas-capture-mode [format]
    • Experimental. Captures images from canvas data instead of screenshots. See canvas capture mode. Can provide an optional image format (e.g. png), otherwise it uses the saved image's extension, or defaults to png if the format is not specified or supported. Can prefix the format with immediate: (e.g. immediate:png) to immediately capture pixel data after rendering, which is sometimes needed for some WebGL renderers. Specify the canvas using the --selector option, otherwise it defaults to the first canvas in the document.
  • <a name="cli-options-start" href="#cli-options-start">#</a> Start: -s, --start n seconds
    • Runs code for n virtual seconds before saving any frames (default: 0).
  • <a name="cli-options-x-offset" href="#cli-options-x-offset">#</a> X Offset: -x, --x-offset pixels
    • X offset of capture, in pixels (default: 0).
  • <a name="cli-options-y-offset" href="#cli-options-y-offset">#</a> Y Offset: -y, --y-offset pixels
    • Y offset of capture, in pixels (default: 0).
  • <a name="cli-options-width" href="#cli-options-width">#</a> Width: -W, --width pixels
    • Width of capture, in pixels.
  • <a name="cli-options-height" href="#cli-options-height">#</a> Height: -H, --height pixels
    • Height of capture, in pixels.
  • <a name="cli-options-round-to-even-width" href="#cli-options-round-to-even-width">#</a> Round to Even Width: --round-to-even-width
    • Rounds width up to the nearest even number.
  • <a name="cli-options-round-to-even-height" href="#cli-options-round-to-even-height">#</a> Round to Even Height: --round-to-even-height
    • Rounds height up to the nearest even number.
  • <a name="cli-options-transparent-background" href="#cli-options-tr

Related Skills

View on GitHub
GitHub Stars241
CategoryDevelopment
Updated3mo ago
Forks58

Languages

JavaScript

Security Score

97/100

Audited on Dec 19, 2025

No findings