Skip to content

Inspector

Defined in: Inspector.ts:744

Programmatic runtime control and state queries for testing and debugging. The engine does not create one: DebugPlugin or InspectorPlugin installs it under InspectorKey, and debug: true exposes it as window.__yage__.inspector.

new Inspector(engine): Inspector

Defined in: Inspector.ts:1196

EngineRef

Inspector

readonly capture: object

Defined in: Inspector.ts:1174

dataURL: () => Promise<string>

Promise<string>

png: () => Promise<Uint8Array<ArrayBufferLike>>

Promise<Uint8Array<ArrayBufferLike>>

pngBase64: () => Promise<string>

Promise<string>


readonly events: object

Defined in: Inspector.ts:1093

clearLog: () => void

void

getLog: () => EventLogEntry[]

EventLogEntry[]

isEnabled: () => boolean

boolean

setCapacity: (n) => void

number

void

setEnabled: (enabled) => void

Turn event-log recording on/off at runtime. Off means zero per-event allocation: the EventBus tap detaches and recordBusEvent is never called. DebugConfig.eventLog controls the startup default; this is the runtime switch for toggling mid-session.

boolean

void

waitFor: (pattern, options?) => Promise<EventLogEntry>

Resolve the earliest retained match without consuming it, or wait for a future match. Clear the log before an action to require a new event. withinFrames expires after that many completed engine frames; events on the deadline frame match first. Zero searches retained history only. Disposing the Inspector or disabling the log rejects pending waits.

string | RegExp

"scene" | "entity" | "bus"

number

Promise<EventLogEntry>


readonly input: object

Defined in: Inspector.ts:949

clearAll: () => void

void

fireAction: (name, frames) => void

string

number = 1

void

gamepadAxis: (side, value) => void

InspectorGamepadAxisKey

number

void

gamepadButton: (code, pressed) => void

string

boolean

void

hold: (code, frames) => void

string

number

void

keyDown: (code) => void

string

void

keyUp: (code) => void

string

void

mouseDown: (button) => void

0 | 1 | 2

void

mouseMove: (x, y) => void

number

number

void

mouseUp: (button) => void

0 | 1 | 2

void

pointerDown: (button, opts?) => void

Inject a synthetic pointer-down. With opts.id and opts.type: "touch" this drives a multi-touch contact, exercising getPointers(), per-pointer event hooks, and the any-pointer aggregate for MouseLeft.

0 | 1 | 2

InspectorPointerOpts

void

pointerMove: (x, y, opts?) => void

Inject a synthetic pointer-move with full pointer addressing. Pass opts with id / type: "touch" to drive a specific finger; defaults match the primary mouse pointer (same as mouseMove).

number

number

InspectorPointerOpts

void

pointerUp: (button, opts?) => void

0 | 1 | 2

number

void

tap: (code, frames) => void

string

number = 1

void


readonly pointer: object

Defined in: Inspector.ts:1053

Pointer input that reaches @yagejs/ui primitives, by asking the renderer to deliver real pointer events. The renderer’s own event system hit-tests and delivers them, so stacking order, a disabled button’s pointer mode and clipping all apply exactly as they do for a person clicking.

Distinct from Inspector.input, which writes InputManager state and never reaches a user-interface element. The two also differ in timing: a button’s onClick has already run when a verb here returns, because delivery is synchronous, while engine input state reflects the press at the next frame’s drain. Step one frame before asserting on action state.

Requires RendererPlugin. The four verbs that dispatch also require at least one rendered frame; hitTest does not.

These verbs drive one primary mouse pointer. A second finger, a touch or a pen pointer is only reachable through Inspector.input, whose verbs take a pointer id and type and write engine state without going near the user interface.

const hit = inspector.pointer.click("entity-7:UISurface:0/2");
expect(hit.path.some((node) => node.type === "UIButton")).toBe(true);

click: (target, opts?) => InspectorPointerHit

Presses and releases at one point, which is what a UIButton requires to run its onClick.

InspectorPointerTarget

InspectorPointerButtonOpts

InspectorPointerHit

down: (target, opts?) => InspectorPointerHit

Presses a mouse button, left unless opts says otherwise.

InspectorPointerTarget

InspectorPointerButtonOpts

InspectorPointerHit

hitTest: (target) => InspectorPointerHit

Resolves target and reports what is under it, dispatching nothing.

InspectorPointerTarget

InspectorPointerHit

move: (target) => InspectorPointerHit

Moves the pointer, which drives hover state. Takes no button: a move presses and releases nothing, and carries whichever buttons an earlier down left held.

InspectorPointerTarget

InspectorPointerHit

up: (target, opts?) => InspectorPointerHit

Releases a mouse button, left unless opts says otherwise.

InspectorPointerTarget

InspectorPointerButtonOpts

InspectorPointerHit


readonly time: InspectorTime

Defined in: Inspector.ts:775

_completeFrame(): void

Defined in: Inspector.ts:1804

Internal

Expire unmatched waiters after the frame’s events and destruction.

void


addExtension<T>(namespace, api): T

Defined in: Inspector.ts:1441

Register a namespaced extension API for plugin-specific debug helpers.

T extends object

string

T

T


attachSceneEventObserver(scene): void

Defined in: Inspector.ts:1704

Internal

Install token-event observation for one scene. No-op if disabled.

Scene

void


attachTimeController(controller): void

Defined in: Inspector.ts:1666

Internal

DebugPlugin attaches the frozen-time controller through this hook.

InspectorTimeController

void


detachSceneEventObserver(scene): void

Defined in: Inspector.ts:1712

Internal

Clear token-event observation for one scene.

Scene

void


detachTimeController(controller?): void

Defined in: Inspector.ts:1671

Internal

Clear a previously attached time controller.

InspectorTimeController

void


dispose(): void

Defined in: Inspector.ts:1741

Internal

The installer’s teardown releases the event-bus tap through this hook.

void


drive<T>(fn, opts?): Promise<InspectorDriveResult<T>>

Defined in: Inspector.ts:1223

Run fn against the running game with the clock held still and every frame-advancing verb awaitable, then report what happened. The clock is frozen for the duration and returned to the state it was in, and every synthetic input is released afterwards. If a release hook throws, cleanup stops with the clock frozen and its lease held, and the drive rejects.

Nothing thrown by fn escapes: a throw is the result’s error. Missing DebugPlugin throws from the call itself, before anything runs.

const run = await inspector.drive(async ({ input, until }) => {
input.keyDown("KeyD");
const frames = await until(
() => (inspector.getEntityPosition("player")?.x ?? 0) > 950,
);
return { frames };
});

The same callback body works as a @yagejs-tools/lab scenario drive, which adds scene, controls and expect on top of these verbs.

T = void

(ctx) => T | Promise<T>

InspectorDriveOptions

Promise<InspectorDriveResult<T>>


getComponentData(nameOrId, componentClass): unknown

Defined in: Inspector.ts:1601

Get inspectable component data by class name string. The entity is addressed by name or by entity.id, so several same-named entities are individually readable.

string | number

string

unknown


getComponentFacet<K>(component, namespace): unknown

Defined in: Inspector.ts:1494

Read one plugin-owned facet without reflecting component state or taking a scene snapshot. Missing contributors and unavailable facets return undefined. Uses the same contributor and failure policy as snapshot().

K extends string

Component

K

unknown


getEntities(): EntitySnapshot[]

Defined in: Inspector.ts:1608

Get all entities in the active scene as lightweight snapshots.

EntitySnapshot[]


getEntity(nameOrId): EntitySnapshot | undefined

Defined in: Inspector.ts:1568

Find one entity by name or by entity.id. A name matches the first active entity of the active scene. An id (a number, or the string form snapshot() and the event log use) reaches any entity on the scene stack, dormant and inactive included, destroyed excluded. A string is tried as a name first, so a name wins over an id with the same spelling.

string | number

EntitySnapshot | undefined


getEntityCount(): number

Defined in: Inspector.ts:2506

Live entities across every scene on the stack, dormant ones included.

number


getEntityPosition(nameOrId): { x: number; y: number; } | undefined

Defined in: Inspector.ts:1578

Get entity position (from Transform component), addressing the entity by name or by entity.id.

string | number

{ x: number; y: number; } | undefined


getErrors(): ErrorSnapshot

Defined in: Inspector.ts:1650

Get recorded failures from the error boundary.

ErrorSnapshot


getExtension<T>(namespace): T | undefined

Defined in: Inspector.ts:1456

Look up a previously registered extension API by namespace.

T extends object

string

T | undefined


getInputState(): InputStateSnapshot

Defined in: Inspector.ts:1621

Get current input state (keys, pointers, gamepad).

InputStateSnapshot


getSceneStack(): SceneSnapshot[]

Defined in: Inspector.ts:1626

Get scene stack info.

SceneSnapshot[]


getSystems(): SystemSnapshot[]

Defined in: Inspector.ts:1638

Get active system info.

SystemSnapshot[]


hasComponent(nameOrId, componentClass): boolean

Defined in: Inspector.ts:1592

Check if an entity has a component by class name string. The entity is addressed by name or by entity.id.

string | number

string

boolean


recordTokenEvent(scene, eventName, data, entity): void

Defined in: Inspector.ts:1721

Internal

Scene observers forward token events through this method: entity is the emitting entity for a bubbled entity.emit, undefined for a scene.emit.

Scene

string

unknown

Entity | undefined

void


registerFacetContributor(contributor): () => void

Defined in: Inspector.ts:1476

Register an InspectorFacetContributor so a plugin can augment component/entity snapshots with a namespaced facet (e.g. the renderer’s render geometry). Returns an unregister function; call it on plugin teardown. Re-registering a namespace replaces the prior contributor.

InspectorFacetContributor

() => void


removeExtension(namespace): void

Defined in: Inspector.ts:1462

Remove a previously registered extension namespace.

string

void


setEventLogEnabled(enabled): void

Defined in: Inspector.ts:1678

Internal

Enable or disable event log recording.

boolean

void


setSeed(seed): void

Defined in: Inspector.ts:1661

Reseed every scene RNG on the stack and every one created later. Same as engine.sceneRandom.setSeed(seed), which game code calls without going through the Inspector.

number

void


snapshot(): EngineSnapshot

Defined in: Inspector.ts:1507

Full deterministic state snapshot (stable ordering, serializable).

EngineSnapshot


snapshotJSON(): string

Defined in: Inspector.ts:1528

Stable JSON form of snapshot.

string


snapshotScene(nameOrId): WorldSceneSnapshot

Defined in: Inspector.ts:1538

Snapshot one scene by its public scene.name or its inspector-assigned id (snapshot().scenes[].id). Name is tried first. If more than one active scene shares that name, throws rather than guessing — pass the id instead. Falls back to an id match when no scene has that name.

string

WorldSceneSnapshot

Coding agents: fetch https://yage.dev/llms.txt first and prefer the Markdown references it links over these HTML pages. This page's Markdown counterpart is /llms/packages/core.md.