postdoc screenshot


Takes screenshots of pages in Chrome, to see a change rather than read it: at several window widths, in the light and the dark colour scheme, of the whole page or of one element. It waits until each page has finished rendering, as the page checks do.

Without --url, it builds the site and serves the build, like postdoc test. With it, it uses a site that's already running, such as the dev server, which is quicker and shows drafts.

Options:

  • --width <widths> - the window widths, in CSS pixels, separated by commas. Defaults to 1280.
  • --height <height> - the window height. Defaults to 800.
  • --theme <themes> - light, dark or light,dark. Defaults to light. Dark mode is switched on as the page checks do, with the nightwatch.pageChecks.a11y.darkMode settings.
  • --selector <selector> - a CSS selector: only the first element it matches.
  • --full-page - the whole page, not only the window.
  • --url <address> - the address of a running site, such as http://localhost:5173.
  • --out-dir <dir> - without --url, builds into this directory instead of the configured outputPath, which is then left as it is.
  • --output <dir> - where to write the PNG files. Defaults to screenshots.
  • --wait <ms> - how long to wait after a page is ready, for maps, fonts and animations. Defaults to 300.

It prints the path of each file it writes, and exits with 1 when a page doesn't load, such as one that isn't there. It needs Chrome, and selenium-webdriver, which comes with Nightwatch.

Example

sh
npx postdoc screenshot /guide/index.html --width 1280,390 --theme light,dark