UNPKG

anchorbrowser

Version:

The official TypeScript library for the Anchorbrowser API

213 lines 7.31 kB
"use strict"; // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. Object.defineProperty(exports, "__esModule", { value: true }); exports.Sessions = void 0; const tslib_1 = require("../../internal/tslib.js"); const resource_1 = require("../../core/resource.js"); const AllAPI = tslib_1.__importStar(require("./all.js")); const all_1 = require("./all.js"); const ClipboardAPI = tslib_1.__importStar(require("./clipboard.js")); const clipboard_1 = require("./clipboard.js"); const KeyboardAPI = tslib_1.__importStar(require("./keyboard.js")); const keyboard_1 = require("./keyboard.js"); const MouseAPI = tslib_1.__importStar(require("./mouse.js")); const mouse_1 = require("./mouse.js"); const AgentAPI = tslib_1.__importStar(require("./agent/agent.js")); const agent_1 = require("./agent/agent.js"); const RecordingsAPI = tslib_1.__importStar(require("./recordings/recordings.js")); const recordings_1 = require("./recordings/recordings.js"); const headers_1 = require("../../internal/headers.js"); const uploads_1 = require("../../internal/uploads.js"); const path_1 = require("../../internal/utils/path.js"); class Sessions extends resource_1.APIResource { constructor() { super(...arguments); this.all = new AllAPI.All(this._client); this.recordings = new RecordingsAPI.Recordings(this._client); this.mouse = new MouseAPI.Mouse(this._client); this.keyboard = new KeyboardAPI.Keyboard(this._client); this.clipboard = new ClipboardAPI.Clipboard(this._client); this.agent = new AgentAPI.Agent(this._client); } /** * Allocates a new browser session for the user, with optional configurations for * ad-blocking, captcha solving, proxy usage, and idle timeout. * * @example * ```ts * const session = await client.sessions.create(); * ``` */ create(body = {}, options) { return this._client.post('/v1/sessions', { body, ...options }); } /** * Retrieves detailed information about a specific browser session. * * @example * ```ts * const session = await client.sessions.retrieve( * 'session_id', * ); * ``` */ retrieve(sessionID, options) { return this._client.get((0, path_1.path) `/v1/sessions/${sessionID}`, options); } /** * Deletes the browser session associated with the provided browser session ID. * Requires a valid API key for authentication. * * @example * ```ts * const successResponse = await client.sessions.delete( * 'session_id', * ); * ``` */ delete(sessionID, options) { return this._client.delete((0, path_1.path) `/v1/sessions/${sessionID}`, options); } /** * Copies the currently selected text to the clipboard * * @example * ```ts * const response = await client.sessions.copy( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * ); * ``` */ copy(sessionID, options) { return this._client.post((0, path_1.path) `/v1/sessions/${sessionID}/copy`, options); } /** * Performs a drag and drop operation from start coordinates to end coordinates * * @example * ```ts * const response = await client.sessions.dragAndDrop( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * { endX: 500, endY: 300, startX: 400, startY: 200 }, * ); * ``` */ dragAndDrop(sessionID, body, options) { return this._client.post((0, path_1.path) `/v1/sessions/${sessionID}/drag-and-drop`, { body, ...options }); } /** * Navigates the browser session to the specified URL * * @example * ```ts * const response = await client.sessions.goto( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * { url: 'https://www.google.com' }, * ); * ``` */ goto(sessionID, body, options) { return this._client.post((0, path_1.path) `/v1/sessions/${sessionID}/goto`, { body, ...options }); } /** * Retrieves a list of pages associated with a specific browser session. * * @example * ```ts * const response = await client.sessions.listPages( * 'session_id', * ); * ``` */ listPages(sessionID, options) { return this._client.get((0, path_1.path) `/v1/sessions/${sessionID}/pages`, options); } /** * Pastes text at the current cursor position * * @example * ```ts * const response = await client.sessions.paste( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * { text: 'Text pasted via API' }, * ); * ``` */ paste(sessionID, body, options) { return this._client.post((0, path_1.path) `/v1/sessions/${sessionID}/paste`, { body, ...options }); } /** * Retrieves metadata of files downloaded during a browser session. Requires a * valid API key for authentication. * * @example * ```ts * const response = await client.sessions.retrieveDownloads( * 'session_id', * ); * ``` */ retrieveDownloads(sessionID, options) { return this._client.get((0, path_1.path) `/v1/sessions/${sessionID}/downloads`, options); } /** * Takes a screenshot of the current browser session and returns it as an image. * * @example * ```ts * const response = await client.sessions.retrieveScreenshot( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * ); * * const content = await response.blob(); * console.log(content); * ``` */ retrieveScreenshot(sessionID, options) { return this._client.get((0, path_1.path) `/v1/sessions/${sessionID}/screenshot`, { ...options, headers: (0, headers_1.buildHeaders)([{ Accept: 'image/png' }, options?.headers]), __binaryResponse: true, }); } /** * Performs a scroll action at the specified coordinates * * @example * ```ts * const response = await client.sessions.scroll( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * { deltaY: 100, x: 0, y: 0 }, * ); * ``` */ scroll(sessionID, body, options) { return this._client.post((0, path_1.path) `/v1/sessions/${sessionID}/scroll`, { body, ...options }); } /** * Upload files directly to a browser session for use with web forms and file * inputs. * * Files are saved to the session's uploads directory and can be referenced in CDP * commands. * * @example * ```ts * const response = await client.sessions.uploadFile( * '550e8400-e29b-41d4-a716-446655440000', * { file: fs.createReadStream('path/to/file') }, * ); * ``` */ uploadFile(sessionID, body, options) { return this._client.post((0, path_1.path) `/v1/sessions/${sessionID}/uploads`, (0, uploads_1.multipartFormRequestOptions)({ body, ...options }, this._client)); } } exports.Sessions = Sessions; Sessions.All = all_1.All; Sessions.Recordings = recordings_1.Recordings; Sessions.Mouse = mouse_1.Mouse; Sessions.Keyboard = keyboard_1.Keyboard; Sessions.Clipboard = clipboard_1.Clipboard; Sessions.Agent = agent_1.Agent; //# sourceMappingURL=sessions.js.map