Playground API

The playground window exposes JavaScript globals that deploy, measure and browse versions (edge), configure routes (Code), read the output (o), drive the sync (sync), and read and set the selection, the layout and the output settings. Use them in the browser console of the playground tab. An AI agent that works through Agent Folder Share uses the same globals from io.eval.js files.

The globals exist only in the playground editor window, and sync.input only in the output windows of the playground. Deployed pages on RTEdge.net do not have them: a deployed page has request.rt and the edge worker runtime instead.

Where the globals run

ContextWhat it sees
io.eval.js, and the console of the playground tabEvery global on these pages, except sync.input. They run in the playground window.
o.eval.jsThe document of the output, and the sync of the output runtime, with sync.input. With several output windows open, the code runs in each of them and the first reply is the result Experimental.
<script type=worker>None of them. A worker receives request.rt, which the editor supplies through sync.requestRT.
A deployed pageNone of them.

File evals describes the io.eval.js and o.eval.js files and their results.

Interfaces

Code

The deployment configuration: the routes Code.D, the editors Code.W, the title field Code.T, the current URL Code.v and the method Code.edit().

edge

The functions that connect the playground to RTEdge.net, with edge.open().

edge.save.limit()

Deploys the playground to every route in Code.D, or deletes the deployments.

edge.size()

Measures the source, its files and the worker, locally, for a deployed route or for a saved version.

edge.versions()

Lists past deployments, and writes any of them into the agent folder.

o

The output from the side of the playground: the authored source of its elements, its dimensions and its pins.

PinList

The type of o.pins: add, capture, configure and remove pins.

sync

Manual sync, Locate, the hook sync.requestRT for worker request metadata, and the lookup sync.input in the output.

Selection, layout and output settings

sel, title, s.layout, s.Position and more

The selections of the editor, the title of the playground, the arrangement of the panes, and getDimensions(). The same page documents the experimental members of the input editor i.

ovp, oz, ocs and more

The preview of the output under other conditions: viewport, zoom, aspect ratio, colour scheme, native preferences, direction, language, root font size and animation speed.

Quick reference

The loose globals, with the type of their value, whether a read gives the value or a Promise, and the URL key that stores them. Await a Promise getter; await on a plain value is harmless.

GlobalValueA read givesURL key
selAn array of [sl, sc, el, ec, dir]The value|
selX, selXIAn array of stringsThe value
foldsAn array of [a, z, s, x]The value[
titleA stringThe valuetitle
ovp[w, h], or undefined for the PanelThe valueovp
ovfitA booleanThe valueovfit
fitOVP()A function that returns an objectThe object
ozA numberThe valueoz
oar[w, h]The value
setOAR()A function that returns a PromiseA Promise
ocsA string, or undefinedA Promiseocs
orm, opc, ort, ord, odir, olangA string, or undefinedA PromiseThe same names
ofsA number, or undefinedA Promiseofs
oasA numberA Promiseoas

Menu commands and their API calls

Many commands are the script form of an API call. Commands and Keyboard shortcuts list all of them.

CommandKeysAPI
Edge: DeployCtrl+S / ⌘+Sedge.save.limit()
Edge: Deploy with Message…Ctrl+Alt+S / ⌘+Alt+SAsks for a "Commit message", then edge.save.limit({ message })
Edge: Delete…Shift+Deleteedge.save.limit({ path: '/del' })
Edge: Open…Ctrl+E / ⌘+Eedge.open()
Edge: Open All Routes…Ctrl+Shift+E / ⌘+Shift+Eedge.open({ all: true })
Code: Size…Alt+Shift+Sedge.size.open({ mode: 'local' })
Code: Size (Deployed)…Command paletteedge.size.open({ mode: 'deployed' })
Set Routes…Alt+R / ⌘+RCode.edit({ select: '#D > :first-child' })
Sync once, Input → OutputF4sync.output({ force: true, io: { checked: true } })
LoadF5sync.output({ force: true, io: { checked: true }, trigger: 'F5' })
Sync once, Input ← OutputF6sync.editor({ force: true, oi: { checked: true }, trigger: 'F6' })
Toggle Shadow Source MaterializationF7sync.shadowRootMaterializationToggle()
Toggle LocateF8sync.scrollLock
Toggle the Live togglesAlt+I, Alt+Oio.sync, oi.sync
Toggle LayoutAlt+/s.al()
Toggle PanelsAlt+Ps.ap()
Output: SettingsCommand paletteshowOutputSettings()

Using the API from io.eval.js

Write one command to io.eval.js, wait for io.eval.json, and read it before you write the next.

How your code runs and how results are written

Strict mode and the final value Experimental

The source is wrapped in an async function and run in strict mode. If it parses as an expression, that expression is the result; otherwise the last expression statement becomes the result. A const or let is local to one eval: assign globalThis.name = … to keep a value for the next one. Assigning an undeclared identifier throws a ReferenceError. The accessor globals, such as sel, ovp, oz and title, are assignable; a read-only global such as mac throws a TypeError when you assign it.

The result file

io.eval.json holds the result as JSON.stringify(result, null, ' '), with two-space indentation. undefined writes an empty file. The result is awaited before it is written, so a final expression that is a Promise, such as ocs, is resolved. A Promise nested inside the result, as in [fitOVP(), ocs], is written as {}: await it first. NaN and Infinity become null, members whose value is undefined disappear, and functions write nothing.

Errors

A thrown error or a rejection is written as its stack text, or as String(e). A rejection with a value that is not an Error, such as the result that setOAR() rejects with when it is aborted, is written as [object Object]; catch it and return it instead.

Output code Experimental

o.eval.js waits until the output has finished initializing and then runs in every connected output window. An error in the output is thrown again in the playground, with its name, message and stack, and written to o.eval.json.

Calls that wait for a person

Code.edit() resolves only when its dialog closes. edge.save.limit() can open the Code dialog, when there are no routes or a route fails, or the delete confirmation, and then waits for the answer. An io.eval.js that awaits them blocks until a person answers. When you are signed out, edge.save.limit() opens the account dialog but resolves missing-user at once.

Requirements

APINeeds
o.input, sync.inputAgent Folder Share, and an output that is in sync with the editor.
edge.versions.load()Agent Folder Share and a signed-in account. Without a share it throws Agent Folder Share is not active.
The methods of o.pinsAgent Folder Share. Without one they throw Pin API requires an active Agent Folder Share. Images also need Output screen capture, which a person starts.
edge.save.limit()A signed-in account. Without a route in Code.D it asks you for one.
edge.versions()A signed-in account and a route: a non-empty Code.D, or the route option.
o.getDimensions(), oar, setOAR(), ovp, ozThe embedded output, which is not in a tab or popup of its own.
setOAR(), and any wait on animation framesA visible playground tab: browsers pause animation frames in background tabs.

Agent Folder Share needs a browser with FileSystemObserver, in practice Chrome or Edge on desktop, and a playground that is not embedded in another page. Everything else on these pages works without it.

Specifications

Not part of any specification. The Playground API is defined by RTCode.io.

Availability

FeaturePlaygroundRTEdge.netNotes
Every global except sync.inputYesNoPlayground editor window only. Deployed pages do not load the playground runtime.
sync.inputYesNoOutput windows of the playground only, after the first agent call.
o.input, o.pins, edge.versions.load()YesNoNeed Agent Folder Share: Chrome or Edge on desktop.

See also