Your first Cua Driver TypeScript app
Import Cua Driver as a same-process TypeScript SDK and inspect the desktop.
In this tutorial, you will import Cua Driver into a Node application, start a session, and read the desktop size. The driver runs in the Node process; you do not need to start a daemon.
Before you begin#
You need Node.js and a supported interactive macOS, Windows, or Linux desktop. On macOS, the Node host needs Accessibility and Screen Recording permission for the actions it performs.
Create a project and install the published package:
npm init -y
npm install @trycua/cua-driverCreate the application#
Save this as first-driver.mjs:
import {
CaptureScope,
CuaDriver,
EndSessionInput,
GetScreenSizeInput,
StartSessionInput,
} from '@trycua/cua-driver';
const driver = CuaDriver.create(undefined);
const session = 'first-sdk-app';
await driver.startSession(
StartSessionInput.new({
session,
captureScope: CaptureScope.Desktop,
})
);
try {
const metadata = await driver.metadata();
const screen = await driver.getScreenSize(GetScreenSizeInput.new({ session }));
console.log(`cua-driver ${metadata.driverVersion}`);
console.log(screen.text);
} finally {
await driver.endSession(EndSessionInput.new({ session }));
await driver.shutdown();
driver.uniffiDestroy();
}Run it:
node first-driver.mjsThe program prints the loaded driver version and the desktop dimensions. It
also demonstrates the lifecycle every Node application should own: create the
runtime, start and end its sessions, await shutdown(), then release the
generated binding handle with uniffiDestroy().
Next steps#
- Use the SDK in process to capture the desktop and select a capture scope.
- Python and TypeScript SDK reference lists the typed methods, records, and errors.
- SDK, MCP, and process hosting explains when a daemon is useful.