> For the complete documentation index, see [llms.txt](https://docs.blynk.io/en/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.blynk.io/en/html-widget-developer-guide/callbacks.md).

# Callbacks

> Registers, replaces or removes the functions the host calls with live updates.

```js
bridge.setCallbacks(callbacks)  // → void
```

**Parameters**

| Name        | Type             | Required | Description                                                                                                                                      |
| ----------- | ---------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `callbacks` | `object \| null` | yes      | Any of the six callback names below. Omitted keys stay as they are; `null` for a key removes that callback; `setCallbacks(null)` removes all six |

A value that isn't a function or `null` is reported through `sendError`, and that key is skipped.

| Callback                  | Called with                                                                                                                          | Web                                   | Mobile                                             |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------- | -------------------------------------------------- |
| `onValueUpdated`          | One [`ValueObject`](https://docs.blynk.io/en/html-widget-developer-guide/datastreams.md#the-value-object), with the full field set   | ✅ every server push                   | ✅ every server push                                |
| `onThemeUpdated`          | The same object `getTheme()` resolves with                                                                                           | ✅ light/dark and branding changes     | ✅ light/dark (or a reload), and late-loading fonts |
| `onHistoricalDataUpdated` | `{ streams }`, as from `getHistoricalData`                                                                                           | ✅ after a `RANGE_PICKER` subscription | — never emitted                                    |
| `onMapDataUpdated`        | `{ points }`, as from `getMapData`                                                                                                   | ✅ after a `RANGE_PICKER` subscription | — never emitted                                    |
| `onDeviceMetadataUpdated` | One committed [metadata descriptor](https://docs.blynk.io/en/html-widget-developer-guide/device-metadata.md#the-metadata-descriptor) | ✅                                     | ✅                                                  |
| `onError`                 | A human-readable message string                                                                                                      | ✅                                     | ✅                                                  |

**Example**

```js
bridge.setCallbacks({
  onValueUpdated: (v) => applyValue(v.index, v),
  onThemeUpdated: (theme) => applyTheme(theme),
  onHistoricalDataUpdated: ({ streams }) => renderChart(streams),
  onMapDataUpdated: ({ points }) => drawTrack(points),
  onDeviceMetadataUpdated: (descriptor) => renderMetadata(descriptor),
  onError: (message) => showErrorBanner(message)
});

bridge.setCallbacks({ onDeviceMetadataUpdated: null });   // remove one
```

* Register callbacks **before** the initial reads, and make rendering safe to repeat.
* `onDeviceMetadataUpdated` suppresses identical snapshots and gets a shallow copy of the descriptor.
* Synchronous exceptions thrown by a callback are caught and logged; exceptions from `onError` are swallowed. A rejected Promise from an `async` callback is **not** caught — handle it inside the callback.
* `onError` runs only while `isOnErrorEnabled` is `true` (the default).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.blynk.io/en/html-widget-developer-guide/callbacks.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
