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

# Script API Overview

> Author JavaScript logic on a dashboard with the Script tab.

The Script tab lets you add JavaScript logic to a dashboard — react to widget
changes, talk over the realtime channel, read and write the database, and more.
Your code runs in a sandboxed context with a fixed set of globals.

## The sandbox globals

Your script is executed with these variables already in scope — you don't import
anything:

| Global                       | Purpose                                                                 |
| ---------------------------- | ----------------------------------------------------------------------- |
| `widget`                     | Read and control widgets ([reference](/script/widgets-api))             |
| `ws`                         | Send and receive realtime messages ([reference](/script/websocket-api)) |
| `storage`                    | Persist small values on the client ([reference](/script/storage-api))   |
| `db`                         | Query and insert database records ([reference](/script/database-api))   |
| `location`                   | Read device geolocation ([reference](/script/location-api))             |
| `context`                    | Product, device, and user info ([reference](/script/device-context))    |
| `sensor`                     | Product sensor helpers                                                  |
| `usb`                        | Product USB helpers                                                     |
| `pdf`                        | PDF export helpers                                                      |
| `console`                    | Logging — output appears in the script console                          |
| `fetch`                      | Standard `fetch` for HTTP requests                                      |
| `setTimeout` / `setInterval` | Standard timers                                                         |

## A first script

```js theme={null}
// Update a label when a slider changes
widget.on('brightnessSlider', 'change', (value) => {
  widget.setText('brightnessLabel', `Brightness: ${value}%`);
});
```

## When to use scripts

* **Glue logic** between widgets — when one changes, update another
* **Custom realtime handling** — interpret incoming device messages your own way
* **Client-side persistence** — remember a user's last choice
* **Data-driven UI** — query the database and render the result

<CardGroup cols={2}>
  <Card title="widget" icon="gauge" href="/script/widgets-api">
    Values, text, visibility, layout, config, events.
  </Card>

  <Card title="ws" icon="plug" href="/script/websocket-api">
    Realtime send / receive.
  </Card>

  <Card title="db" icon="database" href="/script/database-api">
    Query and insert records.
  </Card>

  <Card title="Events" icon="bolt" href="/script/events">
    The full widget event vocabulary.
  </Card>
</CardGroup>
