
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
screenshothtml
Advanced tools
ScreenshotHTML allow you to take screenshots of HTML code, using Puppeteer (a Chromium-automated-based browser).
⚠️ ScreenshotHTML use headless mode by default, so no navigation window will be visible.
NodeJS 14 (or latest) is required.
# Using npm
npm i screenshothtml
# Or using yarn
yarn add screenshothtml
# Or using pnpm
pnpm i screenshothtml
This library does not support browsers, you can use html2canvas and canvas2image to get a similar result.
var image = await screenshot({ <the options> })
| Option | Type | Example | Description |
|---|---|---|---|
| html | string | <h1>Hello world!</h1> | HTML code to capture |
| maxTimeout | int | 15000 | Maximum time to wait for the page to load (in ms) |
| viewportWidth | int | 1600 | Viewport width |
| viewportHeight | int | 900 | Viewport height |
| autoCloseAfter | int | 100000 | Edit the time (in ms) required before the browser close after the screenshot |
| puppeteerArguments | object | {headless: false} | Add additional arguments passed to Puppeteer while creating the browser |
| waitForDomLoaded | boolean | false | Wait before the DOM finish to load before taking a screenshot, more info here. |
const screenshot = require('screenshothtml')
Main :
screenshot()
Do a screenshot of the HTML code.
Close the browser :
await screenshot.close()
Manually close the browser.
Use the browser :
screenshot.browser
Return the browser instance, as it is used by the library.
Last screenshot :
screenshot.browserLastUse
Return the date corresponding to the last screenshot.
Puppeteer arguments :
screenshot.puppeteerArgs
Return the arguments passed to Chromium while creating the browser, do not confuse with the option puppeteerArguments that is different.
ScreenshotHTML version :
screenshot.version
Return the used version of the library.
You can find examples in the example folder of this repo.
When the environment variable SCREENSHOTHTML_SHOW_STATISTICS is set, statistics about the speed are displayed in the terminal.
Some results on the examples in this repo, tested on my computer.
With the option waitForDomLoaded defined with false:
With the option waitForDomLoaded defined avec true :
Instead of inserting HTML code, you can load a URL by replacing the code by url:<the url of the site>. This also works with localhost.
After a screenshot, the browser is automatically closed after 60 seconds, you can change this time with the option autoCloseAfter (negative number cancel the auto close, and 0 close without waiting).
The browser can also be closed manually with the close() function.
waitForDomLoadedThe option waitForDomLoaded (boolean) can be used to define if the browser should wait for the DOM to be loaded before taking a screenshot. If the value is false (or not defined), the browser will use networkidle0, and when it is activated (true), the screenshots are faster, but some elements and scripts may be not load, which can be useful if the page only contains a simple HTML code.
MIT © Johan
FAQs
Screenshot HTML code, from your NodeJS Code
We found that screenshothtml demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.