Remote data
Keep the layout once and send only the values: {{data.path}} placeholders resolve on
every platform from the app's data or from a URL the widget fetches itself.
Data (data, setWidgetData, source)
{{data.path}} reads a value: {{data.city}}, {{data.days.0.hi}}. Integers print as
integers, whole floats as integers up to 1e21 (21.0 → 21), other numbers as the shortest
decimal without an exponent; a missing value prints nothing. An object printed whole
({{data.obj}}) is JSON, but key order and escaping differ between platforms — don't rely
on its exact text. Placeholders fill strings only
(text, labels, URLs) — numeric fields such as progress.value stay literal.
Three layers, later wins per top-level key:
config.data— defaults in the config.setWidgetData(widgetId, data)— the app updates values without resending the layout.source— JSON the widget fetches itself.
await setWidgetConfig({
data: { city: "London" },
source: {
url: "https://api.example.com/weather?city=London&lang={{locale}}",
refreshMinutes: 30,
headers: { Authorization: "Bearer …" },
},
small: { type: "text", content: "{{data.city}} {{data.temp}}°" },
}, undefined, "weather");
await setWidgetData("weather", { temp: 21 });
source rules: https:// only (http://localhost / 127.0.0.1 exactly for development;
look-alike hosts are refused), GET or POST (body), response a JSON value up to 256 KiB
(of UTF-8 bytes on desktop), refreshMinutes 15–1440 (default 30). The
last good response is cached per placement; a failed fetch keeps it. url, header values
and body may use only {{locale}} and {{instance}} (no {{data.…}}) (one request per placement, see
Instances).
| Platform | Fetch |
|---|---|
| iOS / macOS | In the timeline request (8 s budget), cache in the extension |
| Android | On redraw when due; an inexact RTC alarm redraws when the next fetch is due (not waking the device); a failed fetch retries after refreshMinutes |
| Desktop window | Each time a window opens, then every refreshMinutes; cached under fetched:{id} in the shared store |
| Windows Widgets Board | Not fetched — call setWidgetData from the app |