# Custom widgets Import StreamElements widgets or build your own in Overlay Studio, customize per-layer settings, test them, and publish to OBS. Source: https://docs.domdimabot.com/custom-widgets/ Language: en Documentation index: https://docs.domdimabot.com/llms.txt Custom widgets let you drop StreamElements widgets—or your own custom code—straight into any Overlay Studio layout. Import a widget once, place it as a layer as many times as you like, and configure each layer independently. Both StreamElements widgets and native Dima widgets run inside an isolated sandbox. If you're writing widgets from scratch and want the package spec and Dima SDK reference, read [Building widgets (Dima SDK)](https://docs.domdimabot.com/building-custom-widgets-dima-sdk/index.txt). ## Import a widget Go to **Modules → Overlay Studio**, open an overlay, and click **Import widget**. You can pick a `.zip` or `.rar` archive, select a folder, choose individual files, or drag and drop them into the import box. Many StreamElements widgets ship as `.rar` archives, and Studio handles them just like `.zip` files. Password-protected or split archives aren't supported—extract them on your computer first and select the extracted folder instead. Both archive types support up to 300 files and 8 MB unpacked. A standard StreamElements package includes: | File | What it contains | | ------------ | ----------------------------------------------- | | `widget.ini` | File paths pointing to the rest of the package. | | `html` | The widget's markup and structure. | | `css` | Visual styling. | | `js` | Logic and event handlers. | | `fields` | A JSON object defining the editable settings. | | `data` | A JSON object holding saved setting values. | Studio expects the HTML, CSS, JavaScript, fields, and data files as a set, though `fields` and `data` can be empty if omitted—at least some HTML, CSS, or JavaScript is required. Native Dima widgets can also include a `widget.json` manifest (StreamElements exports usually don't have one). Before confirming the import, Overlay Studio displays the widget's engine and its **Uses:** list—taken from `widget.json` or inferred from StreamElements code—so you can see what live data it requests: * **Chat messages** — incoming messages, deleted messages, and chat clears. * **Follows, subs, Bits and raids** — alert events (tip events appear as a supported category, though real tips don't fire yet). * **Saves its own data** — persistent key/value storage for the widget. * **Commands can control it** — chat commands that send signals the widget responds to. * **Command counters** — reads command-use counts. * **Recent events and stream totals** — recent alerts and session totals. * **Twitch polls and predictions** — current poll and prediction totals without voter identities. * **Goals and their progress** — goals and current progress from the source picked for that layer (the Goals page or your Twitch goals). * **Hype trains** — current hype train, level, progress, and public top contributors. * **Ad breaks** — active ad break and Twitch's ad schedule when available. * **Text-to-speech messages**, **Trigger alerts**, and **Channel-point redemptions** — observes these bot events in real time. * **The pet speaking** — observes when a pet starts and finishes a spoken reply. * **Duels** — observes when duels begin and end. * **Roulette spins** — observes a spin and its final result. * **DimaFX purchases** — observes a DimaFX item when playback begins. Widgets that don't declare any live data receive none—Overlay Studio only delivers the categories listed here. ## Write code in Studio To build a widget right inside the editor, open the Add panel and click **New widget** in the custom widgets list. Name it and choose a starter template: * **Dima SDK** (recommended): includes a `widget.json` manifest and updates settings live without reloading. * **StreamElements-compatible**: uses `onWidgetLoad` and `onEventReceived`, so the same files also work in StreamElements. Click **Start coding**, then **Create widget** to save it and drop it onto your current overlay. New widgets count toward your plan's custom widget limit: Free 1, Premium 5, Pro 25. You can open this same editor for any imported or created widget by clicking **Edit code** in its layer settings. To rename a widget, click the pencil icon labeled **Rename widget**, type the new name, and click **Rename** (or press Enter; Escape cancels). Renaming saves immediately without creating a new version. If `widget.json` still contains the old name, the editor updates it as an unsaved edit—save if you want that new name kept for future imports. Any layer still using the old default widget name updates automatically, while layers you manually renamed keep their custom names. Across the editor tabs you'll find HTML, CSS, JS, **Fields** (`fields.txt`, which controls the right-hand settings panel), **Data** (`data.txt`, the starting values; per-layer edits in the right panel still take priority), and `widget.json`. If a StreamElements widget doesn't have a manifest yet, click **Add widget.json** to generate one from what Studio inferred from its code. The live preview runs your unsaved code at the layer's exact dimensions inside the same sandbox used on stream (on phones, toggle between **Code** and **Preview**). **Try it** sends sample chat messages and alerts—only for categories listed in `widget.json`—and **Restart** reloads the preview. Check the widget log for console output, warnings, and errors. * **Validation & saving:** Broken JSON or files over the size limit count as errors. Tabs show an error badge, and clicking an issue jumps right to its line. Errors block saving while the preview keeps showing the last working build. Settings or values that would be skipped show up as items to double-check without blocking saves. * **Versions & recovery:** Clicking **Save** (or pressing Ctrl/⌘+S) creates a new version. Draft layers in Studio update right away, while live OBS overlays stay on their published version until you publish again. Unsaved edits stay in your browser until you save or discard them and restore when you reopen the editor. If the widget was edited elsewhere (such as another tab) after you opened it, Studio warns you and offers **Save anyway**. **Versions** lists the 10 newest versions plus any version used by a published overlay—click **Open** to load one as unsaved edits, then save to make it active again. * **Keyboard & autocomplete:** Pressing Escape inside the editor doesn't close it; press Escape then Tab to move focus out of the code box. As you type, autocomplete suggests Dima SDK calls, events (along with the `widget.json` `uses` entry they need), handler payload fields, your settings after `Dima.fields.` or inside `{key}` placeholders, StreamElements `SE_API` methods, event details, listener names, and valid keys/values in `widget.json` and Fields. Hover over `Dima` or `SE_API` for quick docs, and press Escape to dismiss the suggestion menu. ## Use your own code editor If you prefer editing locally, open **Use your own code editor** in the preview column and click **Download for your editor**. The downloaded zip bundles `widget.html`, `widget.css`, `widget.js`, `fields.json`, `data.json`, `widget.json` (if present), and `widget.ini` so the package stays re-importable. It also includes `dima.d.ts` and `jsconfig.json` for Dima SDK, event, and setting autocomplete in editors like VS Code, plus a `.vscode` folder with schema checks for `fields.json` and `widget.json`. Once you've made your edits, bring them back with **Load a folder** or **Load files** (accepting `.zip`, `.rar`, or individual files). Only the files you load overwrite their matching tabs as unsaved edits; leaving out `widget.json` keeps your existing manifest. Preview the result, then save. The same archive size limits and password/split-archive rules apply here. Note that in StreamElements widgets, `{key}` placeholders in `widget.js` are swapped before the script executes, so local editors may flag those lines as syntax issues. ## Add and adjust a layer Add your widget from the layer palette and open its **Settings**. Editable fields are grouped into collapsible sections (ungrouped fields live under **General**), and **Find a setting** lets you filter them quickly. A **Changed** badge marks any field that differs from the widget's saved defaults—click **Reset** on a single field or **Reset all** to restore defaults. Settings are stored per layer, so you can place multiple copies of the same widget and style each one differently. **Save draft** stores your layer configuration in the editor, and **Publish live** pushes a snapshot to connected OBS browser sources (subsequent draft edits stay out of OBS until you publish again). If you replace a widget's files later, your customized layer settings stay intact unless the new files drop those fields. Draft layers automatically pick up the updated files, while published overlays keep the version they were published with until you publish them again. ## Commands can control it Any widget declaring `"signals"` in `uses` can react when a chat command fires. Inside the layer's **Settings**, the **Commands** section lists every signal declared in `widget.json` along with its description, sample values, a ready-to-paste response, **Copy**, and **Make a command**. If the widget doesn't declare specific signals, Studio gives you a generic **Any command** option instead. Clicking **Make a command** opens the Commands page in a new tab with the name, response, and description pre-filled (for example, `!feed`). Nothing goes live until you click **Save**. Set access levels and cooldowns as usual—for visual effects, locking a command to mods-only works well. For instance, a pet command might reply `$(user) fed Mochi! $(widget.signal feed &p1)`, posting “Ada fed Mochi!” in chat while triggering the pet animation. Etsy and StreamElements pet widgets pair nicely with commands like `!pet` and `!feed`. Pass command arguments using `&p1`, `&p2`, and `&t` (everything after the command), not `$(1)`. By default, a signal reaches every matching widget across all published overlays open in OBS. When another widget in the same overlay also listens for signals, Studio suggests a targeted response like `$(widget.signal.to "Pet" feed &p1)` so only that layer responds: * Targeting works when the layer name sticks to simple letters, numbers, spaces, and `_ ' . , ! ? -`. Otherwise, Studio warns that other widgets may react and recommends a simpler name. * Two layers sharing the same name will both react, and renaming a layer means updating its commands. Studio flags duplicate layer names and reports how many command signals were skipped recently. Keep these signal rules and limits in mind: * **Where signals work:** Real Twitch chat commands, keywords, referenced commands (`#(name)`), and Chat event messages (such as follow, sub, and raid announcements). Timers, channel-point rewards, roulette, AI requests, and dashboard or docs-assistant tests cannot send signals and return `Error: widget_signal_context_required`. Viewer-typed text resembling `$(...)` is never executed. * **Formatting & limits:** Signal names are lowercased and allow only lowercase letters, digits, and `_`, up to 40 characters (`FOCUS` becomes `focus`, while `pet.feed` returns `Error: invalid_widget_signal_name`). Values max out at 500 characters (`Error: widget_signal_too_long`). Each command run can emit up to 5 signals (shared across referenced commands), capped at 30 signals per channel per 10 seconds—extra signals are silently dropped and counted. * **Delivery:** Duplicate delivery of the same Twitch message won't fire a signal twice. Like chat, signals are live-only and aren't replayed when OBS reconnects. ## Test in Studio Open **Test** and scroll to **Custom widget tests**. Select **Preview** to test inside the editor only, or **OBS** to fire tests to connected published sources (after the usual confirmation prompt, since tests can appear on stream). * **Command signals:** In the **Command signal** row, type a signal name (or click a declared chip), add an optional value, and click **Send signal**. Sending to OBS counts toward the 30-per-10-seconds channel limit and arrives as the broadcaster with source `studio`. * **Chat, alerts & moderation:** Chat tests cover **Viewer**, **Subscriber**, **VIP**, **Moderator**, **You**, **First-time chatter**, **Emotes**, **Reply**, **Long message**, and **!command**. Alert tests cover **Follow**, **Sub**, **Resub**, **Gift sub**, **5 gift subs**, **Bits**, **Raid**, and **Tip** (sample data only; real tip events aren't available yet). Moderation tests include **Delete last message** and **Clear chat**. Any test buttons built into the widget's own settings also send a button event in the preview without triggering a real alert or chat message. * **Bot events & live state:** Whenever a widget in your overlay uses a live-state or bot-event category, the **Bot events** row appears with **TTS message**, **Trigger**, **Channel points**, **Sample poll**, **Sample goals**, **Sample hype train**, **Sample ad break**, **Pet reply**, **Duel**, **Roulette**, and **DimaFX purchase**. Paired events automatically send their second phase about three seconds later. The code editor preview includes the same controls. Sample state sent to OBS stays active for about a minute before reverting to real state, and Studio previews start with your channel's real polls, goals, hype train, and ad state. * **Replay recent chat:** The **Replay recent chat** button in the **Chat** row works in the preview only. It replays the last 20 stored channel messages from oldest to newest as plain text—without emotes, name colors, or badge images—and may include messages deleted by moderators, which is why it never sends to OBS. How live state and bot events behave in widgets: * Widgets read polls/predictions with `Dima.state('polls', handler)`, goals with `Dima.state('goals', handler)`, hype trains with `Dima.state('hypetrain', handler)` (declaring `hypetrain` in `uses`), and ad breaks with `Dima.state('ads', handler)` (declaring `ads` in `uses`). Handlers run once a value is known and again whenever it changes—no callback means the value isn't known yet, not that none exist. * Polls and predictions require enabling their Twitch events via the layer's **Polls & predictions** setup (the same setup shown on the Overlay tab) and never reveal who voted. Goal state only reflects the layer's **Goal data** choice (**Your goals here** or **Your Twitch goals**), includes targets and progress, updates within seconds of changes, refreshes at least once a minute for time-based updates, and never fires goal completion actions. Hype train state is `null` when no train is visible, and the ad schedule can stay `null` when Twitch doesn't provide it. * Most bot events are live-only and aren't replayed after an OBS reconnect. Roulette results come from saved spins and can replay up to two minutes after `endsAt`. TTS fires `start` when audio begins and `end` once when it finishes (unplayed messages fire nothing). Trigger events report which alert fired without sending its media URL or playing media in a custom-widget-only overlay. Channel-point events fire for every redemption, even those without a bot action—always treat redemption input as viewer text and render it with `textContent` or `Dima.escape()`. Test alerts also update session data in both the preview and OBS (Studio pushes updated totals after each OBS test alert). Twitch-sourced goal values do not move for test alerts because Twitch tracks its own goals, though session counts still update. All test events are sample data and never alter your real totals or goals. Remember to publish first if you've edited the widget before sending tests to **OBS**. ## Widget log Inside a widget's **Settings**, **Widget log** captures `console.log` and `Dima.log` output, warnings, and runtime errors. In Studio, it also logs incoming command signals—for example, “Signal feed → pizza from Ada”. Click **Clear log** to wipe current entries. The log holds up to 200 recent entries and drops excess lines if a widget logs too rapidly in one minute. If a widget repeatedly freezes, Studio restarts it and eventually turns it off—fix the code or swap out its files, then reload the overlay. ## StreamElements media After import, Overlay Studio scans for images, videos, and sounds hosted on StreamElements. Files served from `cdn.streamelements.com` or `static.streamelements.com` can be copied into your own storage; links on other hosts remain untouched. * **Copy to my storage**: saves supported files into your Asset Library and updates the widget to load from those copies so your media won't break if StreamElements removes the originals. Copying counts toward your plan's design storage; files larger than 50 MB or files that fail to copy stay linked to StreamElements. * **Keep loading from StreamElements**: keeps the original URLs without using your storage quota, though media could disappear if StreamElements removes a file or the link breaks. You can still copy them later from the widget's settings. ## Export for StreamElements Click **Export for StreamElements** in the widget's settings to download a StreamElements-compatible `.zip` containing `widget.ini`, the original HTML, CSS, JavaScript, and fields files, plus a `data.txt` filled with that layer's current values—ready to import directly into StreamElements. ## Plan limits Each channel can import up to **5 custom widgets on Free**, **20 on Premium**, or **100 on Pro**. This cap counts imported widgets rather than how many overlay layers use them. Deleting a widget deletes its files permanently, so you'll need to remove it from every draft and published overlay using it first. ## Goal data In a layer's settings, pick your source under **Goal data**: **Your goals here** (the Goals page, selected by default) or **Your Twitch goals**. Click **Open Goals** to jump to **Dashboard → Goals** in a new tab. * **StreamElements goal keys:** The **Manual** keys `follower-goal`, `subscriber-goal`, `cheer-goal`, and `tip-goal` read from the first active matching goal in your chosen source, or the first reached goal if none are active. When using Twitch goals, followers map to `follower-goal`, sub goals map to `subscriber-goal` (counts before points), Bits goals map to `cheer-goal`, and `tip-goal` stays at 0 since Twitch has no money goals. Any key without a matching goal returns 0. * **How values are calculated:** For Goals page sources, manual keys report current progress (not the target), counted according to the mode set on the Goals page (since creation, current count, set dates, rolling window, or calendar month). Money values use currency units (such as `12.34`) and include everything counted toward that goal—Bits, subs, and custom items, not just tips. * **Updates:** Goals page changes reach widgets within seconds, while Twitch-sourced goals refresh whenever Twitch updates them. Switching sources restarts the widget in the Studio preview and applies to OBS on your next publish. Existing layers remain on the Goals page by default. Session data also exposes rolling and total counters: * `follower-month`, `subscriber-month`, `cheer-month`, and `raid-month` track the current UTC calendar month. * `follower-total` and `subscriber-total` match your live dashboard totals (follows update as they arrive), while `cheer-total` and `raid-total` cover the last 90 days and can decrease as older events age out. * Subscriber counts count each subscriber once plus gifted subs—so a 5-sub community gift adds 5. * `*-session` spans the current stream (or the last 24 hours if no stream start is available), and `*-week` spans the last 7 days. * Tip event values (`tip-*`) stay at 0 until DomDimaBot tipping launches, though the **Money** `tip-goal` value can still display a Goals page goal when that source is selected. ## Not available yet * Live sync from a local code editor. * Real tip events won't fire custom widgets until DomDimaBot tipping launches (Studio's **Tip** test sends sample data only). * 7TV, BetterTTV (BTTV), and FrankerFaceZ (FFZ) emotes aren't supported. * StreamElements API tokens and StreamElements-only APIs aren't available. ## Safety Every widget runs inside a sandboxed frame. It cannot read your DomDimaBot login, the website, Studio, other layers, or your private overlay link; it cannot open popups, dialogs, downloads, or forms; and it cannot navigate the page. As a best effort, the SDK strips OBS's page-control API before widget code executes, and widgets only receive the live data categories listed under **Uses:**. Still, treat any widget as code that appears on your stream and inspect it before publishing. By default, widgets can load files and scripts from external sites, send public channel data they receive (chat messages, alerts, usernames) to remote servers, expose your streaming PC's IP address to those servers, display arbitrary visuals on stream, and consume CPU and memory. External code can also change after you import the widget. Whenever a package loads outside scripts or styles, the import dialog displays **This widget loads code from other sites**, lists the hosts, warns that external code can change and send received data elsewhere, and provides an opt-in **Block outside connections for this widget** checkbox (layer settings also show **Loads code from …**). **Block outside connections for this widget** is off by default, and you can toggle **Block outside connections** anytime in the layer's **Settings**—only the channel owner controls it, and widget authors cannot override it. When turned on: * Only the widget's own code runs: external scripts from any site (StreamElements included) are blocked, with Google Fonts stylesheets as the sole exception. * Images, fonts, audio, and video load only from DomDimaBot, your copied files, StreamElements' `cdn.streamelements.com` and `static.streamelements.com`, Google Fonts, and Twitch emotes/badges on `static-cdn.jtvnw.net`. * Outbound server connections, sockets, WebRTC, inner frames, and workers are blocked, and attempts to open another page or reload the frame are stopped. * The widget's own code and settings continue working, though widgets relying on external CDNs like cdnjs or jsDelivr or external fonts may break. * Studio's preview enforces the same restriction, and open OBS sources reload immediately when you flip the setting. This stops typical tracking, uploads, and remote code swaps, though it is not airtight against a determined author—for example, data can still leak in the URL of a navigation attempt (stopped after the request fires) or via DNS lookups. In OBS, set **Page permissions** to **No access to OBS** on any browser source showing imported widgets. The default (**Read access to OBS status information**) only exposes live/recording status, whereas higher permissions allow any page in that source—including a widget that bypasses the SDK—to switch scenes or stop your stream.