> ## Documentation Index
> Fetch the complete documentation index at: https://docs.doczilla.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Wait for a dashboard to finish loading

> Capture a JavaScript chart after its data arrives.

A dashboard can render its shell before its charts are ready. Add a readiness marker to the page once the chart has been drawn, then ask Doczilla to wait for that marker.

## Capture before and after the chart is ready

Install the [Doczilla Node SDK](https://docs.doczilla.app/libraries/nodejs.md) with `npm install @doczilla/node`. Set `DOCZILLA_API_KEY` in your environment and run `node capture-dashboard.mjs` alongside `dashboard.html`. This runs two renders so you can compare the results.

```javascript capture-dashboard.mjs theme={null}
import { readFile, writeFile } from 'node:fs/promises'
import Doczilla, { PageOptions, ScreenshotOptions } from '@doczilla/node'

const html = await readFile(new URL('./dashboard.html', import.meta.url), 'utf8')
const apiKey = process.env.DOCZILLA_API_KEY
if (!apiKey) {
  throw new Error('Set DOCZILLA_API_KEY')
}

const doczilla = new Doczilla(apiKey)

const page = { html, waitUntil: PageOptions.waitUntil.DOMCONTENTLOADED }
const screenshot = {
  type: ScreenshotOptions.type.PNG,
  viewport: { width: 720, height: 380 }
}

for (const [filename, options] of [
  ['dashboard-loading.png', {}],
  [
    'dashboard-ready.png', {
      waitForSelector: {
        selector: '#chart[data-chart-ready="true"]',
        options: {
          visible: true,
          timeout: 10000
        }
      }
    }
  ]
]) {
  const image = await doczilla.screenshot.direct({
    page: { ...page, ...options },
    screenshot
  })

  await writeFile(filename, image)
}
```

## HTML

Save the HTML below as `dashboard.html`. A timer simulates a data request. The chart is inserted before the page sets `data-chart-ready`.

> [accordion] Dashboard HTML
>
> <Snippet file="code-group/wait-for-dashboard-html.md" />

## Output

![Weekly orders dashboard displaying Loading chart](https://mintcdn.com/doczilla/Teqhl5ABLAafgT50/images/examples/dashboard-loading.png?fit=max\&auto=format\&n=Teqhl5ABLAafgT50\&q=85\&s=ec9bed22fb8ab3f8ff31a590a5cc7425)

Without a readiness check

![Weekly orders dashboard with seven bars and a total of 457](https://mintcdn.com/doczilla/Teqhl5ABLAafgT50/images/examples/dashboard-ready.png?fit=max\&auto=format\&n=Teqhl5ABLAafgT50\&q=85\&s=668f6beff430b17ed9df8c2602f4209c)

After the chart reports that it is ready

If readiness depends on application state instead of a CSS selector, use a boolean expression with `page.waitForFunction`. Doczilla can continue rendering after either wait times out, so a successful HTTP response can still contain a loading state. See [Page options](https://docs.doczilla.app/api-reference/page-options.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.