> 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/tips-and-gotchas.md).

# Tips & Gotchas

| Topic                                               | Guidance                                                                                                                                                          |
| --------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Register callbacks before initial reads**         | Live updates can arrive before or after your first `getValue` / `getValues`. Register `setCallbacks` first, key rendering on `index`, and make it safe to repeat. |
| **`getValues()` can be empty for two reasons**      | No datastreams assigned — *or*, on web, nothing delivered yet. Render a neutral state and let `onValueUpdated` fill it in.                                        |
| **Value objects always carry the full field set**   | Missing fields default to `null`, `''` or `[]`. Check `type`, never field presence.                                                                               |
| **`value` is a string, or `null`**                  | Even for `INT` and `DOUBLE`. Parse it, and handle `null` before the first push.                                                                                   |
| **ENUM `value` is an index string**                 | Resolve with `v.mappings[idx] ?? v.enumFallbackValue ?? v.value`.                                                                                                 |
| **Compare `type` case-insensitively**               | `v.type.toUpperCase() === 'ENUM'` works on every host.                                                                                                            |
| **`sendValue` gives no confirmation**               | Synchronous and fire-and-forget. Index errors arrive via `onError`; selector errors are also thrown — wrap them in `try/catch`.                                   |
| **Selectors match the name, not the alias**         | `{ name }` matches the datastream name; `{ pin }` matches virtual pins only. On web, resolve selectors after the first value update.                              |
| **`getHistoricalData` always needs `dataStreams`**  | Including `RANGE_PICKER`. 1 to 10 entries, each with an index and a `sourceType`.                                                                                 |
| **`CUSTOM` needs `from < to`**                      | Equal timestamps are rejected, and history spans are capped at 365 days.                                                                                          |
| **Out-of-range history indexes are silent**         | Invalid entries are dropped; only an all-invalid request rejects.                                                                                                 |
| **`offset` is for `RAW_DATA` pagination**           | Keep `period`, `from` and `to` identical and grow `offset` by the points received.                                                                                |
| **`RANGE_PICKER` subscription order**               | Register `onHistoricalDataUpdated` / `onMapDataUpdated` **before** subscribing.                                                                                   |
| **Guard on `info.id`**                              | `getDeviceInfo()` resolves an object even with no bound device; `id` is `null` then.                                                                              |
| **Always give the device image a fallback**         | `image` can be `null` or fail to load — show the name's initial, never a broken-image icon.                                                                       |
| **`status` is a flat string**                       | `'ONLINE'`, `'OFFLINE'`, a custom value or `''`. Compare with `.toUpperCase()`.                                                                                   |
| **Feature-detect newer families**                   | Tags, files, assets and native screens can be missing on an older host. Leave that part out when the method is missing.                                           |
| **Check files yourself before uploading**           | `.png` / `.jpg` / `.jpeg` / `.ico`, 1 B to 10 MiB, one upload at a time. Revoke object URLs you create for blobs.                                                 |
| **Native screens need a user gesture**              | Call `openDeviceInfo()` and friends directly in a click or tap handler, never after an `await`.                                                                   |
| **Dashboard pages are mobile-only and index-based** | `getPages()[i]` ↔ `showPage(i)`. Never pass a page `id`. Guard with `isPageActionsSupported()` **and** `typeof bridge.showPage === 'function'`.                   |
| **Theme colors are already mode-resolved**          | Don't re-derive them from `prefers-color-scheme`; keep CSS fallbacks for the editor only. Derive tints with `color-mix()`.                                        |
| **Check permissions, but tolerate rejection**       | Names a host doesn't accept reject with `invalid_request` — fall back instead of hard-blocking.                                                                   |
| **`logEventId` is a string**                        | 64-bit IDs lose precision as numbers; a number rejects.                                                                                                           |
| **Event text limits**                               | 300 for comments and note titles, 2000 for note descriptions; keep `resolveComment` within 300 for portable widgets.                                              |
| **Storage is per user, per browser or phone**       | Never shared between users, never synced across devices. Plain JSON only; 16 KB per value, 512 KB and 1024 items per account.                                     |
| **Data Engine queries are org-scoped**              | The bound device doesn't limit the rows. `limit: 0` (the default) means the server's row cap.                                                                     |
| **Errors come twice**                               | Requests report through `sendError` before rejecting — in `.catch()` only update state.                                                                           |
| **Branch on `error.code`, not on text**             | Messages are for humans and change; `code` and `details` are the contract.                                                                                        |
| **`isExternalRequestsAllowed()` is `false` on web** | Check before `fetch()`, and handle rejections — CORS can still block a request on mobile.                                                                         |
| **No external scripts in production**               | CDN fonts and icon libraries add latency; inline assets or use system fonts.                                                                                      |
| **No `innerHTML` with bridge data**                 | Values, event text, tag and page names, file names and metadata are untrusted. Use `textContent` / `setAttribute`.                                                |
| **Don't touch the host globals**                    | The app calls the `window.blynk*` functions directly; `destroy()` is how you detach.                                                                              |
| **`overscroll-behavior: none`**                     | Set it on `html, body` so the widget doesn't hijack dashboard scrolling.                                                                                          |
| **`touch-action: manipulation`**                    | Removes the 300 ms tap delay without disabling pinch-zoom.                                                                                                        |
| **`-webkit-user-select: none`**                     | Prevents accidental text selection while the user scrolls the dashboard.                                                                                          |
| **Preview and editor mode**                         | When `isBridgeAvailable()` is `false`, render placeholder content so the widget looks meaningful in the editor.                                                   |


---

# 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/tips-and-gotchas.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.
