Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hyperbrowser/sdk",
"version": "1.0.3",
"version": "1.1.0",
"description": "Node SDK for Hyperbrowser API",
"author": "",
"repository": {
Expand Down
54 changes: 51 additions & 3 deletions src/services/computer-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,36 @@ export class ComputerActionService extends BaseService {
y: number,
button: ComputerActionMouseButton = "left",
numClicks: number = 1,
returnScreenshot: boolean = false
returnScreenshot: boolean = false,
keys?: string[]
): Promise<ComputerActionResponse> {
return this.executeRequest(session, {
action: ComputerAction.CLICK,
x,
y,
button,
numClicks,
keys,
returnScreenshot,
});
}

async clickAtCursor(
session: SessionDetail | string,
button: ComputerActionMouseButton = "left",
numClicks: number = 1,
returnScreenshot: boolean = false,
keys?: string[]
): Promise<ComputerActionResponse> {
return this.executeRequest(session, {
action: ComputerAction.CLICK,
button,
numClicks,
returnScreenshot,
keys,
});
}

async typeText(
session: SessionDetail | string,
text: string,
Expand All @@ -83,6 +101,16 @@ export class ComputerActionService extends BaseService {
});
}

async cursorPosition(
session: SessionDetail | string,
returnScreenshot: boolean = false
): Promise<ComputerActionResponse> {
return this.executeRequest(session, {
action: ComputerAction.CURSOR_POSITION,
returnScreenshot,
});
}

async pressKeys(
session: SessionDetail | string,
keys: string[],
Expand All @@ -98,11 +126,13 @@ export class ComputerActionService extends BaseService {
async drag(
session: SessionDetail | string,
path: Coordinate[],
returnScreenshot: boolean = false
returnScreenshot: boolean = false,
keys?: string[]
): Promise<ComputerActionResponse> {
return this.executeRequest(session, {
action: ComputerAction.DRAG,
path,
keys,
returnScreenshot,
});
}
Expand All @@ -127,18 +157,36 @@ export class ComputerActionService extends BaseService {
y: number,
scrollX: number,
scrollY: number,
returnScreenshot: boolean = false
returnScreenshot: boolean = false,
keys?: string[]
): Promise<ComputerActionResponse> {
return this.executeRequest(session, {
action: ComputerAction.SCROLL,
x,
y,
scrollX,
scrollY,
keys,
returnScreenshot,
});
}

async scrollAtCursor(
session: SessionDetail | string,
scrollX: number = 0,
scrollY: number = 0,
returnScreenshot: boolean = false,
keys?: string[]
): Promise<ComputerActionResponse> {
return this.executeRequest(session, {
action: ComputerAction.SCROLL,
scrollX,
scrollY,
returnScreenshot,
keys,
});
}

async holdKey(
session: SessionDetail | string,
key: string,
Expand Down
22 changes: 22 additions & 0 deletions src/types/computer-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export enum ComputerAction {
PRESS_KEYS = "press_keys",
MOVE_MOUSE = "move_mouse",
SCREENSHOT = "screenshot",
CURSOR_POSITION = "cursor_position",
Comment thread
cursor[bot] marked this conversation as resolved.
SCROLL = "scroll",
TYPE_TEXT = "type_text",
GET_CLIPBOARD_TEXT = "get_clipboard_text",
Expand All @@ -36,6 +37,7 @@ export interface ClickActionParams {
y?: number;
button?: ComputerActionMouseButton;
numClicks?: number;
keys?: string[];
returnScreenshot?: boolean;
}

Expand All @@ -45,6 +47,7 @@ export interface ClickActionParams {
export interface DragActionParams {
action: ComputerAction.DRAG;
path: Coordinate[];
keys?: string[];
returnScreenshot?: boolean;
}

Expand Down Expand Up @@ -74,18 +77,28 @@ export interface ScreenshotActionParams {
action: ComputerAction.SCREENSHOT;
}

/** Parameters for reading the desktop cursor position. */
export interface CursorPositionActionParams {
action: ComputerAction.CURSOR_POSITION;
returnScreenshot?: boolean;
}

/**
* Parameters for scroll action
*/
export interface ScrollActionParams {
action: ComputerAction.SCROLL;
x: number;
y: number;
keys?: string[];
scrollX: number;
scrollY: number;
returnScreenshot?: boolean;
}

/** Parameters for scrolling without moving the desktop cursor. */
export type ScrollAtCursorActionParams = Omit<ScrollActionParams, "x" | "y">;

/**
* Parameters for type text action
*/
Expand Down Expand Up @@ -151,7 +164,9 @@ export type ComputerActionParams =
| PressKeysActionParams
| MoveMouseActionParams
| ScreenshotActionParams
| CursorPositionActionParams
| ScrollActionParams
| ScrollAtCursorActionParams
| TypeTextActionParams
| HoldKeyActionParams
| MouseDownActionParams
Expand Down Expand Up @@ -181,7 +196,14 @@ export interface ComputerActionResponseDataListWindows {
windows: ComputerActionWindow[];
}

/** Desktop cursor coordinates in physical screen pixels. */
export interface ComputerActionResponseDataCursorPosition {
x: number;
y: number;
}

export type ComputerActionResponseData =
| ComputerActionResponseDataCursorPosition
| ComputerActionResponseDataClipboardText
| ComputerActionResponseDataListWindows;

Expand Down
3 changes: 3 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ export {
PressKeysActionParams,
MoveMouseActionParams,
ScreenshotActionParams,
CursorPositionActionParams,
ScrollAtCursorActionParams,
ScrollActionParams,
TypeTextActionParams,
ComputerActionParams,
Expand All @@ -343,6 +345,7 @@ export {
ListWindowsActionParams,
ComputerActionWindow,
ComputerActionResponseDataListWindows,
ComputerActionResponseDataCursorPosition,
} from "./computer-action";
export { FetchParams, FetchResponse, FetchResponseData, FetchStatus } from "./web/fetch";
export {
Expand Down
Loading