Working with AI

Browser agents

Letting an AI agent drive the live web editor through Chrome, Playwright or the DevTools protocol.

A browser agent is an AI that controls a real browser: it reads the page, runs JavaScript and takes screenshots. Pointed at the Trisgine editor, it can build and test scenes for you.

What the agent needs

  1. A browser with WebGPU (Chrome or Edge), with the editor open: https://editor.trisgine.com.
  2. The ability to evaluate JavaScript in that tab. Almost every agent tool has this:
ToolHow it runs JS in the page
Claude in Chrome / other browser extensionstheir "run JavaScript" tool
Playwright (or the Playwright MCP server)page.evaluate(() => tgDebug.scene())
Puppeteerpage.evaluate(...)
Chrome DevTools ProtocolRuntime.evaluate with awaitPromise: true
You, by handDevTools console (F12)
  1. Screenshots, if you want the agent to see the result. Page screenshots work. Reading the WebGPU canvas from page JavaScript usually gives blank pixels, so let the tool capture the tab.

Why not just click?

The editor's UI is drawn by the engine onto one <canvas>. There are no HTML buttons for an agent to find, so clicking by coordinates is fragile. Use the APIs instead:

  • window.tgDebug: read and change the editor (scenes, entities, selection, scripts, pixel art, play mode). Full reference.
  • window.tgInput: press gameplay keys and move the mouse (tgInput.key('w', true)).
  • window.tgImport: import files from JavaScript (File objects), exactly like a drag and drop.

If you must click a widget, tgDebug.widget('Toolbar.Play') returns its rectangle on the page, so you can aim at its centre. That's more robust than guessing pixels.

Ground rules that save time

  • Wait for boot. window.tgReady === true means the engine is up.
  • Things apply on the next frame. sceneLoad queues the load, so poll tgDebug.scene() until current changes. In a background tab the browser slows frames to about 1 per second; keep the editor tab visible, or call Module._tgWebRunOneFrame() to advance a frame by hand.
  • Play mode is temporary. Make edits while stopped (tgDebug.simStop()). Anything that changes during play is reset on stop.
  • First-person movement needs the mouse over the Simulation panel. Before injecting W, move the (synthetic) pointer to the centre of tgDebug.widget('Simulation.Content'). Scripts' KeyDown doesn't need this.
  • Read the answers. Every call returns JSON. scriptEditorCommit returns {ok, errors:[{line,message}]}; import returns imported / refused / warnings.

A first session

Ask your agent something like:

Then, in the page:

js
tgDebug.entities();               // {entities:[{id,name},…]}
tgDebug.entityCreate('Cube');     // {ok:true, id:18, name:"Cube", undoable:true}
tgDebug.selectByName('Cube');     // {selected:true, id:18, name:"Cube"}
tgDebug.entity('Cube').position;  // {x:0, y:1, z:0}

Security note

These APIs exist on every editor page and act with your browser's permissions and storage. Only run agent scripts you trust, the same as pasting anything into DevTools.