Skip to content

Devtools

@hamur/devtools adds a toolbar to every page of hamur dev and a panel that shows what the app is made of and what it is doing: routes, loader data, state, config, storage, assets, timing, build size and logs. It is plain DOM, custom elements and CSS, with no UI library, so it looks and works the same with every adapter.

It is for hamur dev only. In a build, in hamur typegen and with devtools.enabled: false the module registers nothing, no file of it reaches .output/, and <app.baseURL>_hamur/devtools/ answers 404.

Install

hamur init writes both steps. In an existing app, install the package as a dev dependency and add it to modules.

sh
bun add -d @hamur/devtools
ts
import type { DevtoolsOptions } from "@hamur/devtools"
import { defineConfig } from "hamur"
import devtools2 from "@hamur/devtools"

const devtools = { shortcut: "shift+alt+d", placement: "bottom-center" } satisfies DevtoolsOptions

export default defineConfig({
  framework: "html",
  modules: [devtools2],
  devtools,
})

The devtools keys

KeyDefaultMeaning
devtools.enabledtruefalse registers nothing
devtools.shortcut"shift+alt+d"opens and closes the panel on the page, and closes it inside the panel, except while you type in a field. Modifiers ctrl, alt, shift and meta, each at most once, joined by +, then one key: a to z, 0 to 9 or f1 to f12, in any case. false turns the shortcut off
devtools.placement"bottom-center"where the toolbar sits: "bottom-center", "bottom-left", "bottom-right", "top-center", "top-left" or "top-right". The choice you make in the panel's settings wins

A wrong value stops the start with devtools.enabled must be a boolean (got "yes"), devtools.shortcut must be a key combination such as "shift+alt+d", or false (got "shift+alt") or devtools.placement must be one of "bottom-center", "bottom-left", "bottom-right", "top-center", "top-left", "top-right" (got "middle").

The toolbar and the panel

The toolbar is one <hamur-devtools> element at the end of <body>, drawn in a shadow root, so nothing of your CSS reaches it and none of its CSS reaches your page. It holds a Hamur button that opens the panel, one button for each devtools app and the render-mode badge, <route name> · <mode>. With the toolbar on the page, the badge of devServer.indicator is not drawn separately.

The panel is a page at <app.baseURL>_hamur/devtools/. The toolbar shows it in a frame at the bottom of the page, which keeps its state while closed. The frame stays open, on the same tab, across a reload, an HMR reload and a dev server restart; the browser tab remembers that in sessionStorage under hamur:devtools:view, and closing the panel clears the open state. You can open the address in a browser tab as well. Tabs that read the page you are looking at (Payload, Plugins, Timeline, Audit, SEO) then say Open this tab from the app page, with your shortcut in brackets in most of them; every other tab works. #/<tab name> in the address selects a tab.

The panel's settings, opened from its footer, belong to you and not to the repository: hidden tabs, tab order, theme (system, light or dark), scale (0.75 to 1.5), toolbar placement, panel height, the panel's floating rectangle and the toolbar button's place. They are kept in your browser's localStorage under hamur:devtools, and a missing or broken value reads as the defaults.

Moving, resizing and docking

  • Drag any edge or corner of the frame to resize it. The first move or resize makes it float.
  • Drag the panel's header to move it. A double click on the header docks it back at the bottom, with its kept height.
  • Drag the toolbar button anywhere on the page. A drag shorter than 4 px is a click. The place wins over devtools.placement.
  • Positions are clamped into the viewport (the panel is at least 240 by 120 px) on load and when the window is resized.
  • Settings, Reset position drops the floating rectangle and the button's place.
  • The Open in its own window button in the header opens the panel in a window of its own and closes the frame. It reads the page through a BroadcastChannel, so every tab works except Timeline, Audit and SEO, which say Open the panel in the page for this tab. Closing that window does not bring the frame back.

Tabs

The sidebar groups the built-in tabs. A tab another module registers goes under Modules, in the order of registration. @hamur/mail registers Mail, which lists the messages hamur dev wrote and renders a template with props you type: see Mail. A Page tab reads the open page; the others read the dev server or the server process.

GroupTabShows
AppOverviewthe versions of hamur, the adapter, the library and Bun; the counts of pages, server routes, modules, app plugins and server plugins
AppPagesevery page route with its pattern, file, layout, middleware, loader file and route rules; the match chain of the page on screen with each route's loader data and the navigator's pending state; a box that runs the router's own matcher; a click navigates
AppPayload and statethe loader data of each matched route, the useState keys and values (editable as JSON), the async-data entries with status and error and a refresh button, and the payload's size in bytes. A Page tab
AppConfigthe public runtime config (editable in dev), the private runtime config masked until you click it, the app config and the resolved hamur.config as a tree you can search
ServerServer routeseach server route with its method, pattern, file, middleware and route rules, and a request form (params, query, headers, JSON or form body, cookies) that sends the request to the app and shows status, headers, time and the body
ServerStoragethe storage mounts, their keys by prefix, and an editor for an item (JSON, text or bytes as hex) with save and delete. A write from any code to a listed mount appears while the tab is open
ServerAssetsthe files of public/ and the public assets modules add, with size, a preview of images, fonts and text, image dimensions and a copy-URL button; drop a file to upload it to public/ (50 MB at most). Module assets are read-only
ServerTasksevery task with its file, schedules and next run, and queued listeners marked; a Run button with a payload box; the last 200 runs with trigger, status, duration, payload and result or error; the delayed enqueue runs still waiting, each with a Cancel button. See Tasks
ServerAuthorizationonly when the app has a server/policies/ folder: each policy with its effect, id, scope and file:line, the schema, the last 200 checks with the policies that decided, and a form that explains one decision for a principal you type. See Authorization
PerformanceTimelineclient events (navigation, route middleware, loaders, useFetch and useAsyncData runs, chunk loads, hydration) with the server spans of the same request nested under them, and a Hooks view with the calls and total time of each build, app and server hook. A Page tab, and devServer.timing must be on
PerformanceAnalyzea button that runs a client build in a temporary folder and shows the treemap and the JavaScript of each route (raw and gzip); two saved runs side by side with the change per chunk and per route
PerformancePluginsthe app plugins with their setup time in dev, and the server plugins with their file
PerformanceModuleseach installed module with its name, version, configKey and resolved options, with secrets redacted
DebugInspectthe transform chain of a module (below) and every #hamur/* virtual module and .hamur/ template with its contents
DebugTerminals and logsthe server log stream with filters by level and request id, and the last 1000 lines of each process that startDevProcess runs, with restart and kill
DebugAuditrules on the current page, such as a missing lang, an image without alt, a button without a name, a duplicate id or a skipped heading level. Each finding names its element and the source file, and Highlight outlines it on the page. A Page tab
DebugSEOhow the page's head shows as an X, Facebook, LinkedIn and Slack card, and which of title, description, og:image, canonical and lang are missing. A Page tab

Two packages add a tab to the Modules group: @hamur/scripts adds Scripts (each script with its source, trigger, status timeline and consent state) and @hamur/db adds Database (the tables, 50 rows per page, a SQL box and the status of each migration).

Every file a tab shows, such as app/pages/blog/[slug].tsx:12, is a link that opens it in your editor.

Devtools apps

A devtools app is a button on the toolbar that draws on the page itself. Hamur adds one, Open component source: it outlines the element under the pointer with the file of the component that wrote it, and a click opens that file at the line. A toggle switches to outlining every island with its component name and hydration directive. In hamur dev each adapter marks the root element of a component with data-hamur-src="<file>:<line>:<column>"; a build never adds it. Writing a devtools tab shows how a module adds an app.

Open in editor

POST <app.baseURL>_hamur/open-in-editor opens a file in your editor. The links of the error overlay, of the devtools panel, of the hydration panel and of the Open component source app all call it. The body is JSON, { "file": "app/pages/index.tsx", "line": 12, "column": 3 }, with file relative to the app root or absolute and line and column defaulting to 1. The file must be inside the app or one of its layers (a path outside is 403 <file> is outside the app) and exist (404 <file> does not exist). A bad body is 400 open-in-editor needs { file, line?, column? }, and the answer is 204 once the editor was started. Like every dev data route it works only from your own machine, or from a device that has the dev token.

Hamur picks the editor from your environment. It has no config key, because the editor is yours and hamur.config.ts is committed.

  1. HAMUR_EDITOR, used as given.
  2. VISUAL, then EDITOR, unless the command is a terminal editor (vi, vim, nvim, nano, emacs, micro, hx, kak, pico, ed, or emacsclient with -t, -nw or --tty), which would take over the terminal of the dev server.
  3. The first of code, cursor, zed, webstorm and subl that is on your PATH.

With none of them, the answer is 501 No editor found; set HAMUR_EDITOR. The value is split on whitespace into a command and its leading arguments, and quotes keep a path with spaces together. No shell runs.

sh
HAMUR_EDITOR="code --reuse-window" hamur dev
HAMUR_EDITOR='"/Applications/My Editor/bin/code" --wait' hamur dev

The file and position go in the form that the command's name needs: -g <file>:<line>:<column> for code, code-insiders, codium, cursor and windsurf; <file>:<line>:<column> for zed and subl; --line <line> --column <column> <file> for webstorm, idea, phpstorm, pycharm, goland, rubymine, rider and clion; the bare <file> for any other command.

Listing routes

hamur routes [root] [--json] scans the app, with no build and no server, and prints the server routes, then the pages, each block in the order the request handler tries them. One line for each route holds <METHOD or PAGE>, the pattern, the name and the file relative to the root; a server route with no method shows *. With --json it prints the DevRouteTable of useDevRouteTable and nothing else. In hamur dev, GET <app.baseURL>_hamur/routes answers the same table as JSON (with Accept: application/json) or as one HTML table. The Pages and Server routes tabs read it.

Inspecting a module

hamur inspect <file> [root] [--target client|server] runs one module through the transform chain of a build and prints its final text, so you see what the build does to a page: the compiled code after every transform. The target is client unless you pass --target server. A file that is not a module of the app fails with hamur inspect: <file> is not a module of this app.

sh
hamur routes
hamur routes --json
hamur inspect app/pages/index.tsx
hamur inspect app/pages/index.tsx --target server

For the steps in between, hamur dev --debug or devServer.inspect records each step of the chain for each module and side: the plugin, the loader it received, the text it returned and the time it took. GET <app.baseURL>_hamur/inspect lists the recorded modules, and ?file=<path relative to the root>&target=client|server shows each step with a line diff against the step before. The Inspect tab frames that page. Without recording it answers 404 Transform recording is off; start hamur dev with --debug or set devServer.inspect.

The dev token

The devtools and the dev routes expose your resolved config, private runtime config, storage items and database rows, and they can write files and start programs. hamur dev therefore answers them only to a request from the same origin that comes from your own machine. A request from another site gets 403 Cross-site request to <path> refused, and a request from another device, through a proxy or through a tunnel gets 403 <path> needs the dev token on this device; open a URL with ?hamur-dev-token=<token> as hamur dev printed it.

The dev token is made when hamur dev starts and kept across its restarts. When the server listens on a host that is not loopback (--host), hamur dev prints [hamur] On another device, open a URL once with ?hamur-dev-token=<token> to use the devtools. Open any URL of the app with ?hamur-dev-token=<token> on that device. The server answers 303 to the same address without it and sets a cookie that is worth nothing to another app on the same host, and from then on that device can use the devtools. A wrong token is 403 Wrong dev token. The runner removes that cookie from every request it passes on, so no loader, server route or log sees it.

Chrome workspace

With devServer.chromeWorkspace on (the default), a request from localhost, 127.0.0.1 or ::1 for /.well-known/appspecific/com.chrome.devtools.json answers { "workspace": { "root", "uuid" } }. root is the folder hamur dev runs in, which is the app root, or the common directory of the app and a layer outside it, and uuid stays the same across restarts. Chrome DevTools offers to map that folder as a workspace, so an edit you make in its Sources panel saves to your files. false answers 404. A build has no such route. The same Bun option is on, so Chrome finds the folder with no further setup.

Library devtools extensions

The browser extension of each library keeps working next to the panel. In hamur dev the adapter hands the extension what it needs, and a build adds nothing of it.

AdapterIn hamur dev
reactreact-dom's development build registers its renderer with window.__REACT_DEVTOOLS_GLOBAL_HOOK__ when the extension has installed it before the client loads
vuethe app is handed to __VUE_DEVTOOLS_GLOBAL_HOOK__, and __VUE_PROD_DEVTOOLS__ is true; in a build it is false
preactthe client imports preact/debug, which the extension reads; a production client does not
sveltecomponents compile with dev: true, in a build with dev: false
solidsolid-js resolves to its development build, in a build to the production build
htmlnone: there is no library and no extension

Next