This repository contains small utilities to take screenshots of Grafana dashboards using browser automation. There are two variants:
grafana-screenshot.js— Playwright-based implementationgrafana-screenshot-puppeteer.js— Puppeteer-based implementation
Both scripts support bearer-token authentication and are intended to produce a single full-page PNG screenshot of a Grafana dashboard.
Install dependencies for the approach you want to use.
Playwright (default):
npm install
npx playwright installPuppeteer (optional):
npm install puppeteer# Playwright (npm script)
npm run grafana-screenshot <grafana-url> <bearer-token> [output-path]
# Playwright (direct)
node grafana-screenshot.js <grafana-url> <bearer-token> [output-path]
# Puppeteer (npm script)
npm run grafana-screenshot-puppeteer <grafana-url> <bearer-token> [output-path]
# Puppeteer (direct)
node grafana-screenshot-puppeteer.js <grafana-url> <bearer-token> [output-path]npm run grafana-screenshot https://grafana.example.com/d/abc123/my-dashboard eyJrIjoiYWJjZGVmZ2hpamsiLCJuIjoidGVzdCIsImlkIjoxfQ== dashboard-screenshot.pnggrafana-url: Full URL to the Grafana dashboard or pagebearer-token: Grafana API token for authenticationoutput-path: Optional output file path (default:grafana-screenshot.png)
- Bearer token authentication (Authorization: Bearer )
- Automatically measures actual content dimensions from the page container element (
main.css-1d1v5u1-page-container#pageContent) when present - Sets an optimal viewport/window-size to force Grafana to render all panels at once (avoids panels that render only when visible)
- Full-page PNG screenshots only (HTML snapshot saving was removed)
- Works with both Playwright and Puppeteer variants (see files above)
- Conservative default waits and progressive scrolling are used to ensure lazy-loaded panels render (total wait ~20–30s depending on dashboard complexity)
- Basic error handling and informative console logs
- Go to Grafana → Configuration → API Keys
- Create a new API key with appropriate permissions
- Copy the token and use it as the bearer token parameter
// Playwright variant
const { takeGrafanaScreenshot } = require('./grafana-screenshot');
await takeGrafanaScreenshot('https://grafana.example.com/d/dashboard-id', 'your-bearer-token', 'output.png');
// Puppeteer variant
const { takeGrafanaScreenshotPuppeteer } = require('./grafana-screenshot-puppeteer');
await takeGrafanaScreenshotPuppeteer('https://grafana.example.com/d/dashboard-id', 'your-bearer-token', 'output-puppeteer.png');