Computer JavaScript SDK
@midscene/computer provides Device implementations for local desktops (ComputerDevice) and remote RDP desktops (RDPDevice), along with ComputerAgent, which inherits all AI methods from the base Agent.
Imports and API overview
In most cases, use a factory function to create and connect a Device in one step: agentForComputer() for the local desktop (backed by ComputerDevice), or agentForRDPComputer() for a remote Windows desktop over RDP (backed by RDPDevice). If you need to configure and manage the Device and Agent instances separately, construct them explicitly.
agentForComputer()
Connects to the local desktop (controlling the primary display by default) and returns a ComputerAgent bound to ComputerDevice. options accepts both shared Agent settings and local Device settings (agentFromComputer is a deprecated compatibility alias).
agentForRDPComputer()
Connects to a remote Windows desktop over RDP and returns a ComputerAgent bound to RDPDevice. host is required; see RDP options below for additional connection settings. The default backend requires FreeRDP to be installed on the machine running the script, and a reachable remote Windows host with RDP enabled. Each RDP session is treated as a single remote display.
ComputerDevice / RDPDevice / ComputerAgent
When constructing ComputerDevice or RDPDevice explicitly, call await device.connect() before passing the Device to ComputerAgent. Pass device-specific settings to the Device constructor; the second argument of ComputerAgent accepts shared Agent options.
Configuration options
Both agentForComputer() and agentForRDPComputer() accept shared Agent options. To register custom actions, pass customActions to the factory function or Device constructor; see Integrate with any interface for details.
Local desktop options
displayId?: string— ID of the display to control. UseComputerDevice.listDisplays()to query available displays. Default: the primary display.customActions?: DeviceAction<any>[]— Custom actions registered for the Agent planner to invoke.keyboardDriver?: 'applescript' | 'libnut'— Keyboard event backend on macOS. Default:'applescript'(wider compatibility); set to'libnut'for faster keystroke injection when supported by the target application.keyboardModifierDelay?: number— Delay in milliseconds after each modifier key state change and primary key press when using the locallibnutkeyboard driver (must be a finite non-negative number). Default:0. Modifiers includeControl,Shift,Alt, andCommand, so this delay applies to keyboard shortcuts as well as the implicitShiftused for uppercase letters during sequential typing (and shifteden-USpunctuation whenkeyboardLayout: 'en-US'is set). Has no effect on direct RDP input or the macOS'applescript'driver. See Forward keyboard input through desktop clients.keyboardLayout?: 'en-US'— Enables base-key mapping for shifteden-USpunctuation during sequential typing with the locallibnutdriver (uppercase Latin letters do not require this setting). Other layouts retain the backend's default behavior. Has no effect on direct RDP input or the macOS'applescript'driver.headless?: boolean— On Linux, set totrueto start a virtual display via Xvfb, enabling desktop automation on headless servers and CI environments (can also be enabled viaMIDSCENE_COMPUTER_HEADLESS_LINUX=true). Default:false.xvfbResolution?: string— Resolution of the Xvfb virtual display. Default:'1920x1080x24'.
Keyboard input options
keyboardTypeDelay?: number— Minimum delay in milliseconds between keystrokes (must be a finite non-negative number). Default:undefined. In'legacy'mode, a positive value causes local and RDP Computer Agents to emit text one Unicode code point at a time (sending real key events on local desktops); when omitted or set to0, local'legacy'input uses clipboard paste to avoid interference from the active system IME. An action-levelkeyboardTypeDelaypassed toaiInput()overrides the Agent-level default (pass0to restore clipboard paste for that single action).inputStrategy?: 'legacy' | 'sequential' | 'bulk'— Default text input strategy forInputactions. Default:'legacy':'sequential': Uses real key events locally and makes one backend call per Unicode code point over RDP. Use this strategy when setting a positivekeyboardTypeDelay.'bulk': Performs a single clipboard paste locally and makes a single backend call over RDP. RequireskeyboardTypeDelayto be omitted or set to0.
Agent-level input options also apply to Input actions planned by agent.ai() / agent.aiAct(), so you do not need to call aiInput() explicitly:
RDP options
host: string— Remote Windows hostname or IP address (required).port?: number— RDP port. Default:3389.username?: string/password?: string— Login credentials for the remote session.domain?: string— Windows domain. Default:undefined.localAddress?: string— Local source IP address to bind for the RDP TCP connection (useful when the host machine has multiple outbound network routes). Default:undefined.adminSession?: boolean— Whether to request a remote admin session when permitted by the server. Default:false.ignoreCertificate?: boolean— Whether to skip TLS certificate validation (useful for self-signed certificates). Default:false.securityProtocol?: 'auto' | 'tls' | 'nla' | 'rdp'— RDP security negotiation protocol. Default:'auto'.desktopWidth?: number/desktopHeight?: number— Requested remote desktop resolution. When omitted, the session size is negotiated between the RDP client and server.
Displays and environment checks
ComputerDevice.listDisplays()
Lists all displays connected to the local machine. Pass a returned id to agentForComputer({ displayId }) to target a specific display.
checkComputerEnvironment()
Checks whether the local desktop environment is ready, returning the OS platform, display count, and availability (available). If available is false, inspect error for details.
Lifecycle
The Agent manages Device cleanup and report finalization. Each Device instance belongs to a single Agent.
As a result, your local desktop and applications remain untouched after destroying a ComputerDevice, whereas managed Xvfb virtual displays and remote RDP connections are closed automatically.
Platform support and limitations
- Local desktop automation requires the appropriate screen recording, accessibility, or display service permissions; see Desktop environment setup.
headless(Xvfb) is supported on Linux only.keyboardDriverapplies to macOS only;keyboardModifierDelayandkeyboardLayoutapply only to the locallibnutdriver and have no effect on direct RDP connections.

