inspector

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Kite DOM Inspector

The Kite DOM Inspector is a web-based debugging tool that allows you to inspect the internal DOM tree, computed styles, and layout coordinates of a running Kite application.

Usage

Install the inspector after creating your engine:

insp, err := devtools.Install(eng, devtools.Options{})
if err != nil {
    return err
}
log.Printf("Inspector listening on %s", insp.ServerAddr())

Once your application is running, the inspector is available via the F12 hotkey (by default). When pressed, it will automatically attempt to open your default web browser to the dashboard URL. If the browser does not open, navigate to the address printed in the logs (typically http://127.0.0.1:8080).

Port Handling

If the requested port is already in use, the inspector will automatically find an available random port and log the new address.

Features

  • Live DOM Tree: View the logical DOM hierarchy in real-time. The tree updates automatically via Server-Sent Events (SSE) whenever a frame is rendered.
  • Hot-key Access: Press F12 to open the inspector browser window.
  • Dynamic Port Selection: Automatically fallback to an available port if the default one is occupied.
  • Node Selection: Click on any node in the tree to view its details.
  • Computed Styles: Inspect the fully resolved computed styles for the selected node.
  • Layout Coordinates: View the absolute bounding box (X, Y, Width, Height) of the selected node in terminal cells.

How it Works

The inspector hooks into the Kite engine's OnFrameRendered lifecycle hook. Every time a frame is committed, the inspector:

  1. Traverses the current DOM tree.
  2. Calculates absolute bounding boxes by walking the fragment tree.
  3. Serializes the state to JSON.
  4. Broadcasts the update to all connected web clients via SSE.

Documentation

Overview

Package inspector captures snapshots of a running Kite application's DOM, layout fragments, and element styles for the DevTools inspector. Mini-plugins implement Extension and register with Inspector.RegisterExtension to contribute data to each snapshot.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionExtension

type ActionExtension interface {
	Extension
	HandleAction(eng *engine.Engine, action string, params json.RawMessage) (any, error)
}

ActionExtension is an optional interface for extensions that handle interactive RPC actions dispatched from their mini-plugin UI (POST /extensions/{id}/action).

type BreakTokenSnapshot

type BreakTokenSnapshot struct {
	ChildIndex int `json:"childIndex"`
}

type ClusterSnapshot

type ClusterSnapshot struct {
	Text       string `json:"text"`
	Width      int    `json:"width"`
	BreakClass string `json:"breakClass"`
}

type Extension

type Extension interface {
	Name() string
	Title() string
	GetPayload(eng *engine.Engine) any
	UIScript() []byte
}

Extension is implemented by all DevTools mini-plugins. Each extension provides its ID (Name), tab label (Title), snapshot payload (GetPayload), and frontend JavaScript module (UIScript, served at GET /extensions/{id}/plugin.js).

type ExtensionSnapshot

type ExtensionSnapshot struct {
	ID      string `json:"id"`
	Title   string `json:"title"`
	Payload any    `json:"payload,omitempty"`
}

type FragmentSnapshot

type FragmentSnapshot struct {
	Name       string              `json:"name"`
	Offset     geom.Point          `json:"offset"`
	Size       geom.Size           `json:"size"`
	Clusters   []ClusterSnapshot   `json:"clusters,omitempty"`
	BreakToken *BreakTokenSnapshot `json:"breakToken,omitempty"`
	Children   []*FragmentSnapshot `json:"children,omitempty"`
}

type Inspector

type Inspector struct {
	// contains filtered or unexported fields
}

func New

func New(eng *engine.Engine) *Inspector

func NewWithServerAddr

func NewWithServerAddr(eng *engine.Engine, addr string) *Inspector

NewWithServerAddr creates an Inspector associated with a bound server address.

func (*Inspector) GetExtension

func (i *Inspector) GetExtension(id string) Extension

func (*Inspector) RegisterExtension

func (i *Inspector) RegisterExtension(ext Extension)

func (*Inspector) ServerAddr

func (i *Inspector) ServerAddr() string

ServerAddr returns the bound DevTools HTTP address, or "" when no server is running.

func (*Inspector) TakeSnapshot

func (i *Inspector) TakeSnapshot() *InspectorPayload

type InspectorPayload

type InspectorPayload struct {
	DebugXRay    bool                `json:"debugXRay"`
	DOM          *NodeSnapshot       `json:"dom"`
	Overlays     []*NodeSnapshot     `json:"overlays,omitempty"`
	Fragments    *FragmentSnapshot   `json:"fragments"`
	OverlayFrags []*FragmentSnapshot `json:"overlayFragments,omitempty"`
	Extensions   []ExtensionSnapshot `json:"extensions,omitempty"`
}

type NodeSnapshot

type NodeSnapshot struct {
	Kind        string            `json:"kind"`
	Name        string            `json:"name"`
	ID          string            `json:"id,omitempty"`
	Class       string            `json:"class,omitempty"`
	IsUA        bool              `json:"isUA,omitempty"`
	Rect        geom.Rect         `json:"rect"`
	ScrollX     int               `json:"scrollX,omitempty"`
	ScrollY     int               `json:"scrollY,omitempty"`
	Disabled    bool              `json:"disabled,omitempty"`
	Text        string            `json:"text,omitempty"`
	TextContent string            `json:"textContent,omitempty"`
	Computed    *style.Computed   `json:"computed,omitempty"`
	Default     style.Style       `json:"default"`
	Raw         style.Style       `json:"raw"`
	Intrinsic   style.Style       `json:"intrinsic"`
	Fragment    *FragmentSnapshot `json:"fragment,omitempty"`
	Children    []*NodeSnapshot   `json:"children,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL