Skip to content

Your first widget

Every development build of Toolblox includes Hello, world!, a small working widget to start from. It adds a page with two stat tiles and a button, built from the same components the app uses. This tutorial walks through it, turns a copy of it into your own widget, and covers what happens between a folder appearing and activate running, how to pick up code changes, where your log lines go, and how to get the app back when a widget breaks it.

Hello, world! is about 40 lines. Later tutorials expand on it: pages and screens, slots and styles, storage and state, and processes.

A module widget is a folder (later, a ZIP package) with two required files:

  • widget.json, the manifest. It names the widget and declares "module": "main.js".
  • main.js, an ES module that exports activate and, optionally, deactivate.

Toolblox imports main.js into the app window itself, not into a sandboxed frame, and calls activate with the host API object. That object gives the widget the app’s React instance, the app’s UI components, live app state, navigation, storage, logging, and every IPC method with all permissions granted. Module widgets are full-trust by design: safety comes from catalogue review, signed and hash-pinned packages, safe mode, and error boundaries, not from limits on the API. The one thing a widget never receives is a Roblox session cookie; those stay in Rust for widgets and for the Toolblox interface alike.

Hello, world! lives in examples/hello_world/.

You need a development build of Toolblox. Release builds only load widgets installed from the signed catalogue, so an unpacked folder never loads in a downloaded copy of the app. See Development for prerequisites; the short version is:

Terminal window
npm install
npm run tauri dev

npm run tauri dev compiles the Rust host in debug mode and starts the Vite dev server for the interface. Debug builds differ from release builds in three ways that matter here:

  • They skip the startup update check, so the app opens straight away.
  • They report the canary channel, which shows the widgets folder at the bottom of the Widgets page and a -canary suffix on the version in the sidebar.
  • They accept widget folders without the .installed.json record that catalogue installs write. A release build rejects such a folder with “Widget … is missing install metadata.”

Widgets live in the widgets folder inside the Toolblox data folder:

Platform Widgets folder
Windows %LOCALAPPDATA%\Toolblox\widgets
macOS ~/Library/Application Support/Toolblox/widgets

In a development build you don’t need to remember this: open Widgets in the sidebar and scroll to the bottom. A panel reads “Development builds also load unpacked widgets from this folder.” with the exact path and a copy button.

Debug builds also honour the TOOLBLOX_DATA_DIR environment variable. When it’s set, Toolblox uses that folder as its data folder, so widgets live in $TOOLBLOX_DATA_DIR/widgets. This is useful for keeping test accounts, settings, and widget data apart from the copy of Toolblox you use day to day. Accounts’ Roblox sessions are still kept in the operating system’s credential store.

Terminal window
$env:TOOLBLOX_DATA_DIR = "$HOME\toolblox-dev-data"
npm run tauri dev

The first time a development build starts, it adds Hello, world! to the widgets folder. It appears in the Installed section of the Widgets page, enabled, and in the sidebar under Widgets. Select it to open its page, titled “Hello, world!” The title is the name in widget.json; the page itself is empty.

Toolblox adds it only once, and records that in a hidden .example-added file in the widgets folder. Uninstalling it sticks. To get it back, install it from the Catalogue section, which in development builds lists the repository’s example and catalogue widgets (see Testing the catalogue locally). Release builds never include it.

  • Directorywidgets/
    • Directoryhello_world/
      • widget.json
      • main.js
      • LICENSE

The manifest, widget.json:

hello_world/widget.json
{
"schemaVersion": 1,
"id": "hello_world",
"name": "Hello, world!",
"version": "1.0.0",
"description": "The example widget in development builds. Start a new widget from it.",
"module": "main.js"
}

Each field is checked by WidgetManifest::validate in src-tauri/src/widgets.rs:

  • schemaVersion must be 1.
  • id is 1 to 64 lowercase letters, digits, and underscores. Hyphens and capitals are rejected. The folder name must be identical to it: Toolblox finds the manifest by scanning every folder, but serves the module from <widgets folder>/<id>/main.js.
  • name is 1 to 80 characters. It’s the sidebar label and the page title.
  • version must be valid SemVer, such as 1.0.0. 1.0 is rejected.
  • module must be exactly main.js at the package root. Other names and paths are rejected.

Hello, world! needs no permissions, so it declares none. Module widgets receive every permission at run time regardless, but the catalogue requires the declared list to match what the widget does, and the install dialog shows it to the user. The Manifest reference covers every field.

The module, main.js:

hello_world/main.js
export function activate(toolblox) {
toolblox.registerPage(function HelloPage() {
return null;
});
}
export function deactivate() {}

A few things in this file are deliberate:

  • Content comes from toolblox.React. To render something, use toolblox.React.createElement, often shortened to h. The widget doesn’t import or bundle React. It uses the app’s own React instance, which is what makes hooks such as React.useState work inside the app’s component tree. A second copy of React breaks hooks with “Invalid hook call”.
  • activate registers, components render. activate is a plain function that runs once. HelloPage is a React component that Toolblox renders whenever the page is open, so hooks such as toolblox.useAppState() and React.useState belong in it, never in activate.
  • The component is a named function. React shows HelloPage in error messages and in the component stack that Toolblox writes to the log when a render fails.
  • toolblox.ui has the app’s own components. Use them, such as toolblox.ui.Button, so a widget matches the app and follows custom themes without its own styles. When you add class names, use ones the app already uses: Tailwind CSS is compiled into the app ahead of time, and a class that doesn’t exist does nothing, silently. See Slots and styles for shipping your own CSS.
  • deactivate is optional. Toolblox removes every page, settings page, slot contribution, stylesheet, and state listener a widget registered when it unloads the widget, so deactivate is only for things Toolblox doesn’t track, such as timers. The storage and state tutorial uses it.
  1. Copy the folder. In the widgets folder, copy hello_world to a folder named after your widget’s ID, such as my_widget. Keep hello_world as a reference.

  2. Rename it. In the copy’s widget.json, set id to the folder name, and give it its own name and description. Keep version at 1.0.0 until you publish.

  3. Bring Toolblox to the front. Toolblox reloads its state when the window gains focus, every 60 seconds, and after most actions. Your widget appears next to Hello, world!, enabled.

    New folders are enabled by default because Toolblox stores the list of disabled widgets, not enabled ones. Turning the switch on a widget’s card off adds it to that list, unloads the module, and stops any processes it started.

  4. Change the page. In the copy’s main.js, make HelloPage return content, then reload the window:

    return toolblox.React.createElement("p", null, "Hello, world!");
  5. Add to the app outside your page. Widgets can add to existing screens through slots. Add this to activate to put a badge under every account’s name on the Accounts page:

    const h = toolblox.React.createElement;
    toolblox.addToSlot("accounts.row", () => h(toolblox.ui.Badge, { variant: "outline" }, "Hello"));

    The slots and styles tutorial covers every slot.

From here, each tutorial adds one capability to the same widget: a settings page and tabs in pages and screens, saved data in storage and state, and helper programs in processes. When it’s ready, list it with one pull request.

Knowing the path from folder to activate makes failures much easier to place. Each step names the code that runs it.

  1. Discovery. get_app_state in src-tauri/src/app_commands.rs calls discover_installed, which reads every folder in the widgets folder whose name doesn’t start with .. For each one it reads widget.json (at most 128 KB), parses it, and validates it. A folder that fails produces an entry in widgetErrors, which the Widgets page shows as a red panel above the Installed section.
  2. Summary. Each valid widget becomes a WidgetSummary in app state. Its moduleUrl points at the widget’s custom protocol: http://widget.localhost/hello_world/main.js on Windows, where WebView2 serves custom schemes over HTTP, and widget://localhost/hello_world/main.js on macOS. The protocol handler in widget_protocol.rs only serves files that resolve inside the widget’s folder, only to the main window, and with Cache-Control: no-store.
  3. Session. The app shell calls syncWidgetModules in src/widgets/host.tsx whenever the set of enabled module widgets changes. For each newly enabled widget it calls open_widget with the module surface. Rust creates a session with a random ID and every permission, because modules run in the app window. toolblox.request sends that session ID with each IPC call. If the session can’t be opened, the module still loads, and every request call throws “The widget session isn’t open.”
  4. Import. The shell runs import(moduleUrl). The app’s Content Security Policy allows scripts from the widget origin, so the module and anything it imports from its own folder load.
  5. Activation. The shell builds the host API for this widget with createApi and calls activate(toolblox). It awaits the returned promise, so an async activate can load stored data before it registers anything.
  6. Rendering. registerPage stores HelloPage in the widget registry and notifies the shell, which re-renders. When the route is /widgets/hello_world, the shell renders the component inside an error boundary.

If the import or activate throws, Toolblox writes “Module failed to load: …” with the stack to the log under widget:hello_world, and the widget’s card shows Failed to load with the error in its tooltip. Contributions registered before the throw stay registered.

Edit main.js, for example make HelloPage return toolblox.React.createElement("p", null, "Hello again."). Then:

  1. Open the developer tools. Development builds enable them: right-click anywhere in the window and select Inspect.
  2. With the developer tools focused, press Ctrl+R on Windows or Cmd+R on macOS, or run location.reload() in the console.

The window reloads, the startup gate passes immediately because Rust already finished it, and every enabled widget is imported fresh.

Changes to widget.json, such as a new name or description, need no reload. They appear on the next state load, for example when the window regains focus. Changing the id also needs the folder renamed to match.

Toolblox writes one log for the app and its widgets: logs/toolblox.log in the data folder, rotated at 1 MB with three older files kept. To read it, open Settings, find Diagnostics, and select View next to Logs. The page shows the whole log, newest first; Copy copies it and Open folder opens the log folder.

The widget’s records use the target widget:<id>. Add a log line to activate:

void toolblox.log.info("Activated");

After a reload, the log reads:

2026-10-14T09:12:09.880Z INFO widget:hello_world: Activated

toolblox.log has debug, info, warn, and error. Each returns a promise that never rejects. Development builds keep debug lines; release builds keep info and above. Besides your own lines, Toolblox writes these under your widget’s target:

  • “Module failed to load: …” when the import or activate throws;
  • “Render failed: …” with the React component stack when a contribution throws while rendering;
  • “Deactivate failed: …” when deactivate throws;
  • “Request <method> failed: …” when an IPC request returns an error;
  • process starts and stops, and the first 200 lines of each process’s error output.

Before a line is written, Toolblox removes Roblox session cookies, join tickets, launch links, and the values of keys such as authorization, cookie, token, and password, and cuts messages over 8 KB. Redaction is a safety net; don’t log secrets. console.log output only goes to the developer tools console and isn’t kept. See Logs and failures for the full rules.

Every contribution renders inside an error boundary. Make HelloPage throw to see it:

toolblox.registerPage(function HelloPage() {
throw new Error("Not yet");
});

After a reload, the page shows an inline alert, “Hello, world! failed to render. (Error: Not yet)”, in place of the widget’s content, and the rest of the app keeps working. The log gets a “Render failed” line with the component stack.

Error boundaries can’t help with everything a full-trust module can do. An infinite loop in activate, a stylesheet that hides the sidebar, or a replaced screen with no way back can make the app unusable. Safe mode starts Toolblox with every widget off for one session:

  • From a terminal, start Toolblox with --safe-mode. For a development build, arguments after a second -- reach the app:

    Terminal window
    npx tauri dev -- -- --safe-mode
  • From the data folder, create an empty file named safe-mode-next-launch in the data folder, then start Toolblox. It deletes the file as it reads it.

In safe mode a banner reads “Safe mode. Widgets are off for this session.” No module is imported, open_widget refuses every surface, and no widget processes start with the app. The Widgets page still works, so you can turn the broken widget off, then select Restart normally.

While developing you can also hide a widget from Toolblox without deleting it: rename its folder so it starts with a dot, such as .hello_world. Discovery skips hidden folders.

Calling createElement by hand gets unwieldy past a few components. Any bundler that can set the JSX factory works, as long as the factory is the app’s React. The approach below uses esbuild and keeps the source in src/, building main.js at the widget root.

  • Directoryhello_world/
    • widget.json
    • main.js (built)
    • package.json
    • Directorysrc/
      • host.js
      • main.jsx
      • HelloPage.jsx

host.js holds the host API in live bindings that every other file imports. ES module exports are live, so the values assigned in bind are visible to every importer, and esbuild preserves that when it bundles.

src/host.js
export let toolblox;
export let React;
export let ui;
export function bind(api) {
toolblox = api;
React = api.React;
ui = api.ui;
}

A file that contains JSX imports React from host.js, which puts it in scope for the JSX factory:

src/HelloPage.jsx
import { React } from "./host.js";
export function HelloPage() {
return <></>;
}
src/main.jsx
import { bind, toolblox } from "./host.js";
import { HelloPage } from "./HelloPage.jsx";
export function activate(api) {
bind(api);
toolblox.registerPage(HelloPage);
}
export function deactivate() {}
package.json
{
"private": true,
"scripts": {
"build": "esbuild src/main.jsx --bundle --format=esm --target=es2022 --jsx-factory=React.createElement --jsx-fragment=React.Fragment --outfile=main.js",
"watch": "npm run build -- --watch"
},
"devDependencies": {
"esbuild": "^0.25.0"
}
}

Run npm install once, then npm run watch while you work and reload the Toolblox window after each rebuild. The output must be a single ES module (--format=esm) that exports activate, and --bundle inlines your other files so main.js doesn’t depend on src/.

Notes on this setup:

  • --jsx-factory=React.createElement compiles <div /> to React.createElement("div"), using whatever React is in scope. Because components only render after activate has called bind, React is always set by then.
  • Don’t import React from "react" anywhere, and don’t depend on packages that do. The bundle would then contain a second React, and hooks would fail with “Invalid hook call”.
  • App components work in JSX as <ui.Button>, because JSX treats a dotted name as a component reference.
  • TypeScript works the same way: esbuild compiles .tsx files with the same flags. Toolblox doesn’t publish a types package; the API’s shape is createApi in src/widgets/host.tsx, documented on Host API.
  • Leave package.json, src/, and node_modules/ out of the package you publish. See Packaging.
Symptom Cause
The widget doesn’t appear, and the Widgets page shows “Widget … couldn’t load: …” The manifest failed validation. The message names the rule, such as “The widget version isn’t valid SemVer.”
The widget doesn’t appear and there’s no error The folder name starts with ., the folder isn’t directly inside the widgets folder, or the window hasn’t regained focus since you added it.
The card shows Failed to load The import or activate threw. Check the log for “Module failed to load”. A folder name that doesn’t match the id causes a failed import.
“Invalid hook call” A hook ran in activate instead of a component, or the bundle contains its own React.
Code changes don’t show The window wasn’t reloaded. Toggling the widget reuses the cached module.
Styles don’t apply The Tailwind class isn’t used anywhere in the app, so it isn’t compiled.
fetch() fails with a Content Security Policy error The app’s policy only allows connections to the Rust host. Use toolblox.request("network.fetch", …).
The widget works in development but a release build rejects it Release builds load only catalogue installs. See Publishing.