Skip to main content

Sandbox

Properties

PropertyModifierType
displayreadonlystring
streamreadonlyVNCServer

Methods

doubleClick()

doubleClick(): Promise<void>
Double left click on the current mouse position.
Returns
Promise<void>

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

leftClick()

leftClick(): Promise<void>
Left click on the current mouse position.
Returns
Promise<void>

middleClick()

middleClick(): Promise<void>
Middle click on the current mouse position.
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): Promise<void>
Press a key.
Parameters
ParameterTypeDescription
keystringThe key to press (e.g. “enter”, “space”, “backspace”, etc.).
Returns
Promise<void>

rightClick()

rightClick(): Promise<void>
Right click on the current mouse position.
Returns
Promise<void>

screenshot()

Call Signature
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.
Call Signature
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.
Call Signature
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.
Call Signature
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: "up" | "down", amount: number): Promise<void>
Scroll the mouse wheel by the given amount.
Parameters
ParameterTypeDefault valueDescription
direction"up" | "down"'down'The direction to scroll. Can be “up” or “down”.
amountnumber1The amount to scroll.
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.
options{ chunkSize: number; delayInMs: number; }An 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()

Call Signature
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

###### Call Signature

```ts
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?

```ts
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].
I