Sandbox

Properties

PropertyModifierTypeDefault value
displaypublicstring':0'
streampublicVNCServerundefined

Methods

doubleClick()

doubleClick(x?: number, y?: number): Promise<void>

Double left click on the mouse position.

Parameters
ParameterType
x?number
y?number
Returns

Promise<void>

drag()

drag(from: [number, number], to: [number, number]): Promise<void>

Drag the mouse from the given position to the given position.

Parameters
ParameterTypeDescription
from[number, number]The starting position.
to[number, number]The ending position.
Returns

Promise<void>

getApplicationWindows()

getApplicationWindows(application: string): Promise<string[]>

Get the window ID of the window with the given title.

Parameters
ParameterType
applicationstring
Returns

Promise<string[]>

The ID of the window.

getCurrentWindowId()

getCurrentWindowId(): Promise<string>

Get the current window ID.

Returns

Promise<string>

The ID of the current window.

getCursorPosition()

getCursorPosition(): Promise<CursorPosition>

Get the current cursor position.

Returns

Promise<CursorPosition>

A object with the x and y coordinates

Throws

Error if cursor position cannot be determined

getScreenSize()

getScreenSize(): Promise<ScreenSize>

Get the current screen size.

Returns

Promise<ScreenSize>

An ScreenSize object

Throws

Error if screen size cannot be determined

getWindowTitle()

getWindowTitle(windowId: string): Promise<string>

Get the title of the window with the given ID.

Parameters
ParameterTypeDescription
windowIdstringThe ID of the window.
Returns

Promise<string>

The title of the window.

leftClick()

leftClick(x?: number, y?: number): Promise<void>

Left click on the mouse position.

Parameters
ParameterType
x?number
y?number
Returns

Promise<void>

middleClick()

middleClick(x?: number, y?: number): Promise<void>

Middle click on the mouse position.

Parameters
ParameterType
x?number
y?number
Returns

Promise<void>

mousePress()

mousePress(button: "left" | "right" | "middle"): Promise<void>

Press the mouse button.

Parameters
ParameterTypeDefault value
button"left" | "right" | "middle"'left'
Returns

Promise<void>

mouseRelease()

mouseRelease(button: "left" | "right" | "middle"): Promise<void>

Release the mouse button.

Parameters
ParameterTypeDefault value
button"left" | "right" | "middle"'left'
Returns

Promise<void>

moveMouse()

moveMouse(x: number, y: number): Promise<void>

Move the mouse to the given coordinates.

Parameters
ParameterTypeDescription
xnumberThe x coordinate.
ynumberThe y coordinate.
Returns

Promise<void>

open()

open(fileOrUrl: string): Promise<void>

Open a file or a URL in the default application.

Parameters
ParameterTypeDescription
fileOrUrlstringThe file or URL to open.
Returns

Promise<void>

press()

press(key: string | string[]): Promise<void>

Press a key.

Parameters
ParameterTypeDescription
keystring | string[]The key to press (e.g. "enter", "space", "backspace", etc.). Can be a single key or an array of keys.
Returns

Promise<void>

rightClick()

rightClick(x?: number, y?: number): Promise<void>

Right click on the mouse position.

Parameters
ParameterType
x?number
y?number
Returns

Promise<void>

screenshot()

screenshot()
screenshot(): Promise<Uint8Array<ArrayBufferLike>>

Take a screenshot and save it to the given name.

Returns

Promise<Uint8Array<ArrayBufferLike>>

A Uint8Array bytes representation of the screenshot.

screenshot(format)
screenshot(format: "bytes"): Promise<Uint8Array<ArrayBufferLike>>

Take a screenshot and save it to the given name.

Parameters
ParameterTypeDescription
format"bytes"The format of the screenshot.
Returns

Promise<Uint8Array<ArrayBufferLike>>

A Uint8Array bytes representation of the screenshot.

screenshot(format)
screenshot(format: "blob"): Promise<Blob>

Take a screenshot and save it to the given name.

Parameters
ParameterType
format"blob"
Returns

Promise<Blob>

A Blob representation of the screenshot.

screenshot(format)
screenshot(format: "stream"): Promise<ReadableStream<Uint8Array<ArrayBufferLike>>>

Take a screenshot and save it to the given name.

Parameters
ParameterType
format"stream"
Returns

Promise<ReadableStream<Uint8Array<ArrayBufferLike>>>

A ReadableStream of bytes representation of the screenshot.

scroll()

scroll(direction: "down" | "up", amount: number): Promise<void>

Scroll the mouse wheel by the given amount.

Parameters
ParameterTypeDefault valueDescription
direction"down" | "up"'down'The direction to scroll. Can be "up" or "down".
amountnumber1The amount to scroll.
Returns

Promise<void>

wait()

wait(ms: number): Promise<void>

Wait for the given amount of time.

Parameters
ParameterTypeDescription
msnumberThe amount of time to wait in milliseconds.
Returns

Promise<void>

waitAndVerify()

waitAndVerify(
   cmd: string, 
   onResult: (result: CommandResult) => boolean, 
   timeout: number, 
interval: number): Promise<boolean>

Wait for a command to return a specific result.

Parameters
ParameterTypeDefault valueDescription
cmdstringundefinedThe command to run.
onResult(result: CommandResult) => booleanundefinedThe function to check the result of the command.
timeoutnumber10The maximum time to wait for the command to return the result.
intervalnumber0.5The interval to wait between checks.
Returns

Promise<boolean>

true if the command returned the result within the timeout, otherwise false.

write()

write(text: string, options: object): Promise<void>

Write the given text at the current cursor position.

Parameters
ParameterTypeDescription
textstringThe text to write.
optionsobjectAn object containing the chunk size and delay between each chunk of text.
options.chunkSizenumberThe size of each chunk of text to write. Default is 25 characters.
options.delayInMsnumberThe delay between each chunk of text. Default is 75 ms.
Returns

Promise<void>

create()

create(this, opts)
static create<S>(this: S, opts?: SandboxOpts): Promise<InstanceType<S>>

Create a new sandbox from the default desktop sandbox template.

Type Parameters
Type Parameter
S extends typeof Sandbox
Parameters
ParameterTypeDescription
thisS-
opts?SandboxOptsconnection options.
Returns

Promise<InstanceType<S>>

sandbox instance for the new sandbox.

Example
const sandbox = await Sandbox.create()
Constructs

Sandbox

create(this, template, opts)
static create<S>(
   this: S, 
   template: string, 
opts?: SandboxOpts): Promise<InstanceType<S>>

Create a new sandbox from the specified sandbox template.

Type Parameters
Type Parameter
S extends typeof Sandbox
Parameters
ParameterTypeDescription
thisS-
templatestringsandbox template name or ID.
opts?SandboxOptsconnection options.
Returns

Promise<InstanceType<S>>

sandbox instance for the new sandbox.

Example
const sandbox = await Sandbox.create('<template-name-or-id>')
Constructs

Sandbox

Interfaces

SandboxOpts

Configuration options for the Sandbox environment. SandboxOpts

Properties

display?

optional display: string;

Display identifier.

dpi?

optional dpi: number;

Dots per inch (DPI) setting for the display.

resolution?

optional resolution: [number, number];

The screen resolution in pixels, specified as [width, height].