Skip to content

Add JavaScript to a widget

Use client.js for a chart library, canvas or custom interaction that a template cannot provide.

Keep markup and styles in the widget

The script runs as JavaScript in a separate frame, with the widget template and CSS. Query tiledash.root to find your elements. Mark library-owned content with data-script so template updates preserve it.

<span class="reading" data-script></span>

Listen for live context

The context event runs immediately and whenever the allowed data changes. Declare cap in the script context permissions for this example.

tiledash.on('context', (context) => {  const label = tiledash.root.querySelector('.reading');  if (label) {    label.textContent = context.cap?.measure_power?.text      ?? 'No power reading available';  }});

Use JavaScript syntax

client.js uses the browser’s JavaScript: const/let, functions, arrow callbacks, objects, arrays, optional chaining, promises and async/await. HdScript’s restricted handler grammar does not apply here. Access to the app and Homey still goes through the supported tiledash API and declared permissions.

Handle actions and unavailable scripts

Listen to click or hd-change and call tiledash.call. Template data-hd-on handlers do not execute inside the frame. Actions require a recent press inside it. Keep a useful template fallback: scripts do not run in every browser or on e-ink, lite pages and server-rendered pictures.