gologin-agent-browser-cli 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +318 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +336 -0
- package/dist/commands/back.d.ts +2 -0
- package/dist/commands/back.js +12 -0
- package/dist/commands/check.d.ts +2 -0
- package/dist/commands/check.js +17 -0
- package/dist/commands/click.d.ts +2 -0
- package/dist/commands/click.js +17 -0
- package/dist/commands/close.d.ts +2 -0
- package/dist/commands/close.js +12 -0
- package/dist/commands/cookies.d.ts +2 -0
- package/dist/commands/cookies.js +23 -0
- package/dist/commands/cookiesClear.d.ts +2 -0
- package/dist/commands/cookiesClear.js +12 -0
- package/dist/commands/cookiesImport.d.ts +2 -0
- package/dist/commands/cookiesImport.js +18 -0
- package/dist/commands/current.d.ts +2 -0
- package/dist/commands/current.js +9 -0
- package/dist/commands/dblclick.d.ts +2 -0
- package/dist/commands/dblclick.js +17 -0
- package/dist/commands/doctor.d.ts +2 -0
- package/dist/commands/doctor.js +31 -0
- package/dist/commands/eval.d.ts +2 -0
- package/dist/commands/eval.js +30 -0
- package/dist/commands/fill.d.ts +2 -0
- package/dist/commands/fill.js +18 -0
- package/dist/commands/find.d.ts +2 -0
- package/dist/commands/find.js +86 -0
- package/dist/commands/focus.d.ts +2 -0
- package/dist/commands/focus.js +17 -0
- package/dist/commands/forward.d.ts +2 -0
- package/dist/commands/forward.js +12 -0
- package/dist/commands/get.d.ts +2 -0
- package/dist/commands/get.js +19 -0
- package/dist/commands/hover.d.ts +2 -0
- package/dist/commands/hover.js +17 -0
- package/dist/commands/open.d.ts +2 -0
- package/dist/commands/open.js +67 -0
- package/dist/commands/pdf.d.ts +2 -0
- package/dist/commands/pdf.js +18 -0
- package/dist/commands/press.d.ts +2 -0
- package/dist/commands/press.js +19 -0
- package/dist/commands/reload.d.ts +2 -0
- package/dist/commands/reload.js +12 -0
- package/dist/commands/screenshot.d.ts +2 -0
- package/dist/commands/screenshot.js +22 -0
- package/dist/commands/scroll.d.ts +2 -0
- package/dist/commands/scroll.js +25 -0
- package/dist/commands/scrollIntoView.d.ts +2 -0
- package/dist/commands/scrollIntoView.js +17 -0
- package/dist/commands/select.d.ts +2 -0
- package/dist/commands/select.js +18 -0
- package/dist/commands/sessions.d.ts +2 -0
- package/dist/commands/sessions.js +15 -0
- package/dist/commands/shared.d.ts +7 -0
- package/dist/commands/shared.js +51 -0
- package/dist/commands/snapshot.d.ts +2 -0
- package/dist/commands/snapshot.js +16 -0
- package/dist/commands/storageClear.d.ts +2 -0
- package/dist/commands/storageClear.js +13 -0
- package/dist/commands/storageExport.d.ts +2 -0
- package/dist/commands/storageExport.js +24 -0
- package/dist/commands/storageImport.d.ts +2 -0
- package/dist/commands/storageImport.js +20 -0
- package/dist/commands/tabClose.d.ts +2 -0
- package/dist/commands/tabClose.js +21 -0
- package/dist/commands/tabFocus.d.ts +2 -0
- package/dist/commands/tabFocus.js +21 -0
- package/dist/commands/tabOpen.d.ts +2 -0
- package/dist/commands/tabOpen.js +13 -0
- package/dist/commands/tabs.d.ts +2 -0
- package/dist/commands/tabs.js +17 -0
- package/dist/commands/type.d.ts +2 -0
- package/dist/commands/type.js +18 -0
- package/dist/commands/uncheck.d.ts +2 -0
- package/dist/commands/uncheck.js +17 -0
- package/dist/commands/upload.d.ts +2 -0
- package/dist/commands/upload.js +18 -0
- package/dist/commands/wait.d.ts +2 -0
- package/dist/commands/wait.js +41 -0
- package/dist/daemon/browser.d.ts +67 -0
- package/dist/daemon/browser.js +818 -0
- package/dist/daemon/refStore.d.ts +9 -0
- package/dist/daemon/refStore.js +26 -0
- package/dist/daemon/server.d.ts +1 -0
- package/dist/daemon/server.js +313 -0
- package/dist/daemon/sessionManager.d.ts +66 -0
- package/dist/daemon/sessionManager.js +684 -0
- package/dist/daemon/snapshot.d.ts +8 -0
- package/dist/daemon/snapshot.js +285 -0
- package/dist/lib/config.d.ts +3 -0
- package/dist/lib/config.js +58 -0
- package/dist/lib/daemon.d.ts +9 -0
- package/dist/lib/daemon.js +197 -0
- package/dist/lib/errors.d.ts +12 -0
- package/dist/lib/errors.js +63 -0
- package/dist/lib/types.d.ts +407 -0
- package/dist/lib/types.js +2 -0
- package/dist/lib/utils.d.ts +27 -0
- package/dist/lib/utils.js +165 -0
- package/examples/agent-flow.sh +19 -0
- package/package.json +61 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runScrollCommand = runScrollCommand;
|
|
4
|
+
const errors_1 = require("../lib/errors");
|
|
5
|
+
const utils_1 = require("../lib/utils");
|
|
6
|
+
const shared_1 = require("./shared");
|
|
7
|
+
const SCROLL_DIRECTIONS = new Set(["up", "down", "left", "right"]);
|
|
8
|
+
async function runScrollCommand(context, argv) {
|
|
9
|
+
const parsed = (0, utils_1.parseArgs)(argv);
|
|
10
|
+
const direction = parsed.positional[0];
|
|
11
|
+
const maybePixels = parsed.positional[1];
|
|
12
|
+
const target = (0, utils_1.getFlagString)(parsed, "target");
|
|
13
|
+
const sessionId = (0, utils_1.getFlagString)(parsed, "session");
|
|
14
|
+
if (!direction || !SCROLL_DIRECTIONS.has(direction)) {
|
|
15
|
+
throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser scroll <up|down|left|right> [pixels] [--target <target>] [--session <sessionId>]", 400);
|
|
16
|
+
}
|
|
17
|
+
if (maybePixels && !(0, utils_1.isNumericToken)(maybePixels)) {
|
|
18
|
+
throw new errors_1.AppError("BAD_REQUEST", "scroll pixels must be a number", 400);
|
|
19
|
+
}
|
|
20
|
+
const pixels = maybePixels ? Number(maybePixels) : undefined;
|
|
21
|
+
const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
|
|
22
|
+
const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/scroll`, { direction, pixels, target });
|
|
23
|
+
const targetSuffix = response.target ? ` target=${response.target}` : "";
|
|
24
|
+
context.stdout.write(`scrolled direction=${response.direction} pixels=${response.pixels}${targetSuffix} session=${response.sessionId} url=${response.url}\n`);
|
|
25
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runScrollIntoViewCommand = runScrollIntoViewCommand;
|
|
4
|
+
const errors_1 = require("../lib/errors");
|
|
5
|
+
const utils_1 = require("../lib/utils");
|
|
6
|
+
const shared_1 = require("./shared");
|
|
7
|
+
async function runScrollIntoViewCommand(context, argv) {
|
|
8
|
+
const parsed = (0, utils_1.parseArgs)(argv);
|
|
9
|
+
const target = parsed.positional[0];
|
|
10
|
+
const sessionId = (0, utils_1.getFlagString)(parsed, "session");
|
|
11
|
+
if (!target) {
|
|
12
|
+
throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser scrollintoview <target> [--session <sessionId>]", 400);
|
|
13
|
+
}
|
|
14
|
+
const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
|
|
15
|
+
const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/scrollintoview`, { target });
|
|
16
|
+
(0, shared_1.writeActionResult)(context, "scrolled-into-view", target, response);
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runSelectCommand = runSelectCommand;
|
|
4
|
+
const errors_1 = require("../lib/errors");
|
|
5
|
+
const utils_1 = require("../lib/utils");
|
|
6
|
+
const shared_1 = require("./shared");
|
|
7
|
+
async function runSelectCommand(context, argv) {
|
|
8
|
+
const parsed = (0, utils_1.parseArgs)(argv);
|
|
9
|
+
const target = parsed.positional[0];
|
|
10
|
+
const value = parsed.positional.slice(1).join(" ");
|
|
11
|
+
const sessionId = (0, utils_1.getFlagString)(parsed, "session");
|
|
12
|
+
if (!target || !value) {
|
|
13
|
+
throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser select <target> <value> [--session <sessionId>]", 400);
|
|
14
|
+
}
|
|
15
|
+
const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
|
|
16
|
+
const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/select`, { target, value });
|
|
17
|
+
(0, shared_1.writeActionResult)(context, "selected", target, response);
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runSessionsCommand = runSessionsCommand;
|
|
4
|
+
const utils_1 = require("../lib/utils");
|
|
5
|
+
async function runSessionsCommand(context, argv) {
|
|
6
|
+
(0, utils_1.parseArgs)(argv);
|
|
7
|
+
const response = await context.client.request("GET", "/sessions");
|
|
8
|
+
if (response.sessions.length === 0) {
|
|
9
|
+
context.stdout.write("no sessions\n");
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
for (const session of response.sessions) {
|
|
13
|
+
context.stdout.write(`${(0, utils_1.formatSessionLine)(session)}\n`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ActionResponse, CommandContext, StorageScope } from "../lib/types";
|
|
2
|
+
export declare function resolveSessionId(context: CommandContext, explicitSessionId?: string): Promise<string>;
|
|
3
|
+
export declare function writeActionResult(context: CommandContext, verb: string, target: string, response: ActionResponse): void;
|
|
4
|
+
export declare function parseStorageScope(value: string | undefined): StorageScope | undefined;
|
|
5
|
+
export declare function readJsonFile<T>(context: CommandContext, targetPath: string): T;
|
|
6
|
+
export declare function writeJsonFile(context: CommandContext, targetPath: string, payload: unknown): string;
|
|
7
|
+
export declare function writeJsonStdout(context: CommandContext, payload: unknown): void;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveSessionId = resolveSessionId;
|
|
7
|
+
exports.writeActionResult = writeActionResult;
|
|
8
|
+
exports.parseStorageScope = parseStorageScope;
|
|
9
|
+
exports.readJsonFile = readJsonFile;
|
|
10
|
+
exports.writeJsonFile = writeJsonFile;
|
|
11
|
+
exports.writeJsonStdout = writeJsonStdout;
|
|
12
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
13
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
14
|
+
const errors_1 = require("../lib/errors");
|
|
15
|
+
const utils_1 = require("../lib/utils");
|
|
16
|
+
async function resolveSessionId(context, explicitSessionId) {
|
|
17
|
+
if (explicitSessionId) {
|
|
18
|
+
return explicitSessionId;
|
|
19
|
+
}
|
|
20
|
+
return (await context.client.request("GET", "/sessions/current")).sessionId;
|
|
21
|
+
}
|
|
22
|
+
function writeActionResult(context, verb, target, response) {
|
|
23
|
+
context.stdout.write(`${verb} target=${target} session=${response.sessionId} url=${response.url} snapshot=${response.staleSnapshot ? "stale" : "fresh"}\n`);
|
|
24
|
+
}
|
|
25
|
+
function parseStorageScope(value) {
|
|
26
|
+
if (!value) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
if (value === "local" || value === "session" || value === "both") {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
throw new errors_1.AppError("BAD_REQUEST", "--scope must be one of local, session, or both", 400);
|
|
33
|
+
}
|
|
34
|
+
function readJsonFile(context, targetPath) {
|
|
35
|
+
const absolutePath = (0, utils_1.ensureAbsolutePath)(context.cwd, targetPath);
|
|
36
|
+
try {
|
|
37
|
+
return JSON.parse(node_fs_1.default.readFileSync(absolutePath, "utf8"));
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw new errors_1.AppError("BAD_REQUEST", `Failed to read JSON file ${absolutePath}: ${error instanceof Error ? error.message : String(error)}`, 400);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function writeJsonFile(context, targetPath, payload) {
|
|
44
|
+
const absolutePath = (0, utils_1.ensureAbsolutePath)(context.cwd, targetPath);
|
|
45
|
+
node_fs_1.default.mkdirSync(node_path_1.default.dirname(absolutePath), { recursive: true });
|
|
46
|
+
node_fs_1.default.writeFileSync(absolutePath, `${JSON.stringify(payload, null, 2)}\n`, "utf8");
|
|
47
|
+
return absolutePath;
|
|
48
|
+
}
|
|
49
|
+
function writeJsonStdout(context, payload) {
|
|
50
|
+
context.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
|
|
51
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runSnapshotCommand = runSnapshotCommand;
|
|
4
|
+
const utils_1 = require("../lib/utils");
|
|
5
|
+
async function runSnapshotCommand(context, argv) {
|
|
6
|
+
const parsed = (0, utils_1.parseArgs)(argv);
|
|
7
|
+
const sessionId = (0, utils_1.getFlagString)(parsed, "session");
|
|
8
|
+
const interactive = (0, utils_1.getFlagBoolean)(parsed, "interactive");
|
|
9
|
+
const resolvedSessionId = sessionId ??
|
|
10
|
+
(await context.client.request("GET", "/sessions/current")).sessionId;
|
|
11
|
+
const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/snapshot`, interactive ? { interactive: true } : {});
|
|
12
|
+
context.stdout.write(`session=${response.sessionId} url=${response.url}\n`);
|
|
13
|
+
for (const item of response.items) {
|
|
14
|
+
context.stdout.write(`${(0, utils_1.formatSnapshotItem)(item)}\n`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runStorageClearCommand = runStorageClearCommand;
|
|
4
|
+
const utils_1 = require("../lib/utils");
|
|
5
|
+
const shared_1 = require("./shared");
|
|
6
|
+
async function runStorageClearCommand(context, argv) {
|
|
7
|
+
const parsed = (0, utils_1.parseArgs)(argv);
|
|
8
|
+
const sessionId = (0, utils_1.getFlagString)(parsed, "session");
|
|
9
|
+
const scope = (0, shared_1.parseStorageScope)((0, utils_1.getFlagString)(parsed, "scope"));
|
|
10
|
+
const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
|
|
11
|
+
const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/storage-clear`, { scope });
|
|
12
|
+
context.stdout.write(`origin=${response.origin} scope=${response.scope} session=${response.sessionId} url=${response.url} snapshot=${response.staleSnapshot ? "stale" : "fresh"}\n`);
|
|
13
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runStorageExportCommand = runStorageExportCommand;
|
|
4
|
+
const utils_1 = require("../lib/utils");
|
|
5
|
+
const shared_1 = require("./shared");
|
|
6
|
+
async function runStorageExportCommand(context, argv) {
|
|
7
|
+
const parsed = (0, utils_1.parseArgs)(argv);
|
|
8
|
+
const sessionId = (0, utils_1.getFlagString)(parsed, "session");
|
|
9
|
+
const outputPath = parsed.positional[0];
|
|
10
|
+
const json = (0, utils_1.getFlagBoolean)(parsed, "json");
|
|
11
|
+
const scope = (0, shared_1.parseStorageScope)((0, utils_1.getFlagString)(parsed, "scope"));
|
|
12
|
+
const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
|
|
13
|
+
const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/storage-export`, { scope });
|
|
14
|
+
if (outputPath) {
|
|
15
|
+
const savedPath = (0, shared_1.writeJsonFile)(context, outputPath, response.state);
|
|
16
|
+
context.stdout.write(`${savedPath}\n`);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (json) {
|
|
20
|
+
(0, shared_1.writeJsonStdout)(context, response.state);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
context.stdout.write(`${JSON.stringify(response.state, null, 2)}\n`);
|
|
24
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runStorageImportCommand = runStorageImportCommand;
|
|
4
|
+
const errors_1 = require("../lib/errors");
|
|
5
|
+
const utils_1 = require("../lib/utils");
|
|
6
|
+
const shared_1 = require("./shared");
|
|
7
|
+
async function runStorageImportCommand(context, argv) {
|
|
8
|
+
const parsed = (0, utils_1.parseArgs)(argv);
|
|
9
|
+
const sessionId = (0, utils_1.getFlagString)(parsed, "session");
|
|
10
|
+
const storagePath = parsed.positional[0];
|
|
11
|
+
const scope = (0, shared_1.parseStorageScope)((0, utils_1.getFlagString)(parsed, "scope"));
|
|
12
|
+
const clear = (0, utils_1.getFlagBoolean)(parsed, "clear");
|
|
13
|
+
if (!storagePath) {
|
|
14
|
+
throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser storage-import <storage.json> [--scope <local|session|both>] [--clear] [--session <sessionId>]", 400);
|
|
15
|
+
}
|
|
16
|
+
const state = (0, shared_1.readJsonFile)(context, storagePath);
|
|
17
|
+
const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
|
|
18
|
+
const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/storage-import`, { state, scope, clear });
|
|
19
|
+
context.stdout.write(`origin=${response.origin} localKeys=${response.localKeys} sessionKeys=${response.sessionKeys} session=${response.sessionId} url=${response.url} snapshot=${response.staleSnapshot ? "stale" : "fresh"}\n`);
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runTabCloseCommand = runTabCloseCommand;
|
|
4
|
+
const errors_1 = require("../lib/errors");
|
|
5
|
+
const utils_1 = require("../lib/utils");
|
|
6
|
+
const shared_1 = require("./shared");
|
|
7
|
+
async function runTabCloseCommand(context, argv) {
|
|
8
|
+
const parsed = (0, utils_1.parseArgs)(argv);
|
|
9
|
+
const sessionId = (0, utils_1.getFlagString)(parsed, "session");
|
|
10
|
+
const rawIndex = parsed.positional[0];
|
|
11
|
+
let index;
|
|
12
|
+
if (rawIndex !== undefined) {
|
|
13
|
+
index = Number(rawIndex);
|
|
14
|
+
if (!Number.isInteger(index) || index <= 0) {
|
|
15
|
+
throw new errors_1.AppError("BAD_REQUEST", "tab index must be a positive integer", 400);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
|
|
19
|
+
const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/tabclose`, { index });
|
|
20
|
+
context.stdout.write(`closedTab=${response.closedTabIndex} activeTab=${response.activeTabIndex} session=${response.sessionId} url=${response.url} snapshot=${response.staleSnapshot ? "stale" : "fresh"}\n`);
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runTabFocusCommand = runTabFocusCommand;
|
|
4
|
+
const errors_1 = require("../lib/errors");
|
|
5
|
+
const utils_1 = require("../lib/utils");
|
|
6
|
+
const shared_1 = require("./shared");
|
|
7
|
+
async function runTabFocusCommand(context, argv) {
|
|
8
|
+
const parsed = (0, utils_1.parseArgs)(argv);
|
|
9
|
+
const sessionId = (0, utils_1.getFlagString)(parsed, "session");
|
|
10
|
+
const rawIndex = parsed.positional[0];
|
|
11
|
+
if (!rawIndex) {
|
|
12
|
+
throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser tabfocus <index> [--session <sessionId>]", 400);
|
|
13
|
+
}
|
|
14
|
+
const index = Number(rawIndex);
|
|
15
|
+
if (!Number.isInteger(index) || index <= 0) {
|
|
16
|
+
throw new errors_1.AppError("BAD_REQUEST", "tab index must be a positive integer", 400);
|
|
17
|
+
}
|
|
18
|
+
const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
|
|
19
|
+
const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/tabfocus`, { index });
|
|
20
|
+
context.stdout.write(`tab=${response.tabIndex} session=${response.sessionId} url=${response.url} snapshot=${response.staleSnapshot ? "stale" : "fresh"}\n`);
|
|
21
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runTabOpenCommand = runTabOpenCommand;
|
|
4
|
+
const utils_1 = require("../lib/utils");
|
|
5
|
+
const shared_1 = require("./shared");
|
|
6
|
+
async function runTabOpenCommand(context, argv) {
|
|
7
|
+
const parsed = (0, utils_1.parseArgs)(argv);
|
|
8
|
+
const sessionId = (0, utils_1.getFlagString)(parsed, "session");
|
|
9
|
+
const url = parsed.positional[0];
|
|
10
|
+
const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
|
|
11
|
+
const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/tabopen`, { url });
|
|
12
|
+
context.stdout.write(`tab=${response.tabIndex} session=${response.sessionId} url=${response.url} snapshot=${response.staleSnapshot ? "stale" : "fresh"}\n`);
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runTabsCommand = runTabsCommand;
|
|
4
|
+
const utils_1 = require("../lib/utils");
|
|
5
|
+
const shared_1 = require("./shared");
|
|
6
|
+
async function runTabsCommand(context, argv) {
|
|
7
|
+
const parsed = (0, utils_1.parseArgs)(argv);
|
|
8
|
+
const sessionId = (0, utils_1.getFlagString)(parsed, "session");
|
|
9
|
+
const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
|
|
10
|
+
const response = await context.client.request("GET", `/sessions/${resolvedSessionId}/tabs`);
|
|
11
|
+
context.stdout.write(`session=${response.sessionId} tabs=${response.tabs.length}\n`);
|
|
12
|
+
for (const tab of response.tabs) {
|
|
13
|
+
const prefix = tab.active ? "*" : "-";
|
|
14
|
+
const title = tab.title ? ` title=${JSON.stringify(tab.title)}` : "";
|
|
15
|
+
context.stdout.write(`${prefix} tab=${tab.index} url=${tab.url}${title}\n`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runTypeCommand = runTypeCommand;
|
|
4
|
+
const errors_1 = require("../lib/errors");
|
|
5
|
+
const utils_1 = require("../lib/utils");
|
|
6
|
+
const shared_1 = require("./shared");
|
|
7
|
+
async function runTypeCommand(context, argv) {
|
|
8
|
+
const parsed = (0, utils_1.parseArgs)(argv);
|
|
9
|
+
const target = parsed.positional[0];
|
|
10
|
+
const text = parsed.positional.slice(1).join(" ");
|
|
11
|
+
const sessionId = (0, utils_1.getFlagString)(parsed, "session");
|
|
12
|
+
if (!target || !text) {
|
|
13
|
+
throw new errors_1.AppError("BAD_REQUEST", 'Usage: gologin-agent-browser type <target> <text> [--session <sessionId>]', 400);
|
|
14
|
+
}
|
|
15
|
+
const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
|
|
16
|
+
const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/type`, { target, text });
|
|
17
|
+
(0, shared_1.writeActionResult)(context, "typed", target, response);
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runUncheckCommand = runUncheckCommand;
|
|
4
|
+
const errors_1 = require("../lib/errors");
|
|
5
|
+
const utils_1 = require("../lib/utils");
|
|
6
|
+
const shared_1 = require("./shared");
|
|
7
|
+
async function runUncheckCommand(context, argv) {
|
|
8
|
+
const parsed = (0, utils_1.parseArgs)(argv);
|
|
9
|
+
const target = parsed.positional[0];
|
|
10
|
+
const sessionId = (0, utils_1.getFlagString)(parsed, "session");
|
|
11
|
+
if (!target) {
|
|
12
|
+
throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser uncheck <target> [--session <sessionId>]", 400);
|
|
13
|
+
}
|
|
14
|
+
const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
|
|
15
|
+
const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/uncheck`, { target });
|
|
16
|
+
(0, shared_1.writeActionResult)(context, "unchecked", target, response);
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runUploadCommand = runUploadCommand;
|
|
4
|
+
const errors_1 = require("../lib/errors");
|
|
5
|
+
const utils_1 = require("../lib/utils");
|
|
6
|
+
const shared_1 = require("./shared");
|
|
7
|
+
async function runUploadCommand(context, argv) {
|
|
8
|
+
const parsed = (0, utils_1.parseArgs)(argv);
|
|
9
|
+
const target = parsed.positional[0];
|
|
10
|
+
const files = parsed.positional.slice(1).map((file) => (0, utils_1.ensureAbsolutePath)(context.cwd, file));
|
|
11
|
+
const sessionId = (0, utils_1.getFlagString)(parsed, "session");
|
|
12
|
+
if (!target || files.length === 0) {
|
|
13
|
+
throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser upload <target> <file...> [--session <sessionId>]", 400);
|
|
14
|
+
}
|
|
15
|
+
const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
|
|
16
|
+
const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/upload`, { target, files });
|
|
17
|
+
context.stdout.write(`uploaded files=${response.files.length} target=${target} session=${response.sessionId} url=${response.url} snapshot=${response.staleSnapshot ? "stale" : "fresh"}\n`);
|
|
18
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runWaitCommand = runWaitCommand;
|
|
4
|
+
const errors_1 = require("../lib/errors");
|
|
5
|
+
const utils_1 = require("../lib/utils");
|
|
6
|
+
const shared_1 = require("./shared");
|
|
7
|
+
async function runWaitCommand(context, argv) {
|
|
8
|
+
const parsed = (0, utils_1.parseArgs)(argv);
|
|
9
|
+
const first = parsed.positional[0];
|
|
10
|
+
const sessionId = (0, utils_1.getFlagString)(parsed, "session");
|
|
11
|
+
const text = (0, utils_1.getFlagString)(parsed, "text");
|
|
12
|
+
const urlPattern = (0, utils_1.getFlagString)(parsed, "url");
|
|
13
|
+
const loadState = (0, utils_1.getFlagString)(parsed, "load");
|
|
14
|
+
const body = {};
|
|
15
|
+
if (first) {
|
|
16
|
+
if ((0, utils_1.isNumericToken)(first)) {
|
|
17
|
+
body.timeoutMs = Number(first);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
body.target = first;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (text) {
|
|
24
|
+
body.text = text;
|
|
25
|
+
}
|
|
26
|
+
if (urlPattern) {
|
|
27
|
+
body.urlPattern = urlPattern;
|
|
28
|
+
}
|
|
29
|
+
if (loadState === "load" || loadState === "domcontentloaded" || loadState === "networkidle") {
|
|
30
|
+
body.loadState = loadState;
|
|
31
|
+
}
|
|
32
|
+
else if (loadState) {
|
|
33
|
+
throw new errors_1.AppError("BAD_REQUEST", "wait --load must be load, domcontentloaded, or networkidle", 400);
|
|
34
|
+
}
|
|
35
|
+
if (!body.target && !body.text && !body.urlPattern && !body.loadState && body.timeoutMs === undefined) {
|
|
36
|
+
throw new errors_1.AppError("BAD_REQUEST", "Usage: gologin-agent-browser wait <target|ms> [--text <text>] [--url <pattern>] [--load <state>] [--session <sessionId>]", 400);
|
|
37
|
+
}
|
|
38
|
+
const resolvedSessionId = await (0, shared_1.resolveSessionId)(context, sessionId);
|
|
39
|
+
const response = await context.client.request("POST", `/sessions/${resolvedSessionId}/wait`, body);
|
|
40
|
+
context.stdout.write(`waited session=${response.sessionId} url=${response.url} for=${response.waitedFor}\n`);
|
|
41
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type Locator, type Page } from "playwright";
|
|
2
|
+
import type { AgentConfig, BrowserCookie, CookiesResponse, EvalResponse, GetKind, ProxyConfig, ProxySummary, RefDescriptor, ScrollDirection, SemanticFindAction, SemanticLocatorQuery, SessionRecord, StorageScope, StorageState, TabSummary, WaitLoadState } from "../lib/types";
|
|
3
|
+
export declare function buildConnectUrl(config: AgentConfig, token: string, profileId?: string): string;
|
|
4
|
+
export declare function toPlaywrightCdpUrl(connectUrl: string): string;
|
|
5
|
+
export declare function createQuickProfile(token: string, sessionId: string): Promise<string>;
|
|
6
|
+
export declare function createManagedProfile(token: string, sessionId: string, proxy?: ProxyConfig): Promise<{
|
|
7
|
+
profileId: string;
|
|
8
|
+
proxy?: ProxySummary;
|
|
9
|
+
}>;
|
|
10
|
+
export declare function deleteProfile(token: string, profileId: string): Promise<void>;
|
|
11
|
+
export declare function getCloudLiveViewUrl(token: string, profileId: string): Promise<string | undefined>;
|
|
12
|
+
export declare function getCloudProfileProxy(token: string, profileId: string): Promise<ProxySummary | undefined>;
|
|
13
|
+
export declare function connectToBrowser(config: AgentConfig, token: string, profileId?: string): Promise<Pick<SessionRecord, "browser" | "context" | "page" | "connectUrl">>;
|
|
14
|
+
export declare function navigatePage(page: Page, url: string, timeoutMs: number): Promise<string>;
|
|
15
|
+
export declare function resolveDescriptorLocator(page: Page, descriptor: RefDescriptor): Promise<Locator>;
|
|
16
|
+
export declare function resolveSelectorLocator(page: Page, selector: string, timeoutMs: number): Promise<Locator>;
|
|
17
|
+
export declare function resolveSemanticLocator(page: Page, query: SemanticLocatorQuery, timeoutMs: number): Promise<Locator>;
|
|
18
|
+
export declare function performLocatorAction(page: Page, locator: Locator, action: SemanticFindAction | "focus" | "dblclick" | "select" | "check" | "uncheck", timeoutMs: number, value?: string): Promise<string | undefined>;
|
|
19
|
+
export declare function actionMutatesSnapshot(action: SemanticFindAction): boolean;
|
|
20
|
+
export declare function pressKey(page: Page, key: string, timeoutMs: number): Promise<void>;
|
|
21
|
+
export declare function waitForTarget(locator: Locator, timeoutMs: number): Promise<void>;
|
|
22
|
+
export declare function waitForPageText(page: Page, text: string, timeoutMs: number, exact?: boolean): Promise<void>;
|
|
23
|
+
export declare function waitForPageUrl(page: Page, urlPattern: string, timeoutMs: number): Promise<void>;
|
|
24
|
+
export declare function waitForPageLoad(page: Page, state: WaitLoadState, timeoutMs: number): Promise<void>;
|
|
25
|
+
export declare function readLocatorValue(locator: Locator, kind: GetKind, timeoutMs: number): Promise<string>;
|
|
26
|
+
export declare function scrollPage(page: Page, direction: ScrollDirection, pixels: number): Promise<void>;
|
|
27
|
+
export declare function scrollElement(locator: Locator, direction: ScrollDirection, pixels: number): Promise<void>;
|
|
28
|
+
export declare function scrollLocatorIntoView(locator: Locator, timeoutMs: number): Promise<void>;
|
|
29
|
+
export declare function uploadFiles(locator: Locator, files: string[], timeoutMs: number): Promise<void>;
|
|
30
|
+
export declare function savePdf(page: Page, targetPath: string): Promise<void>;
|
|
31
|
+
export declare function captureScreenshot(page: Page, targetPath: string, timeoutMs: number): Promise<void>;
|
|
32
|
+
export declare function listTabs(session: SessionRecord): Promise<TabSummary[]>;
|
|
33
|
+
export declare function openTab(session: SessionRecord, url: string | undefined, timeoutMs: number): Promise<{
|
|
34
|
+
page: Page;
|
|
35
|
+
tabIndex: number;
|
|
36
|
+
}>;
|
|
37
|
+
export declare function focusTab(session: SessionRecord, index: number): Promise<{
|
|
38
|
+
page: Page;
|
|
39
|
+
tabIndex: number;
|
|
40
|
+
}>;
|
|
41
|
+
export declare function closeTab(session: SessionRecord, index?: number): Promise<{
|
|
42
|
+
page: Page;
|
|
43
|
+
closedTabIndex: number;
|
|
44
|
+
activeTabIndex: number;
|
|
45
|
+
}>;
|
|
46
|
+
export declare function navigateHistory(page: Page, direction: "back" | "forward" | "reload", timeoutMs: number): Promise<string>;
|
|
47
|
+
export declare function readCookies(session: SessionRecord): Promise<CookiesResponse["cookies"]>;
|
|
48
|
+
export declare function importCookies(session: SessionRecord, cookies: BrowserCookie[]): Promise<number>;
|
|
49
|
+
export declare function clearCookies(session: SessionRecord): Promise<number>;
|
|
50
|
+
export declare function exportStorageState(page: Page, scope?: StorageScope): Promise<StorageState>;
|
|
51
|
+
export declare function importStorageState(page: Page, state: StorageState, scope?: StorageScope, clear?: boolean): Promise<{
|
|
52
|
+
origin: string;
|
|
53
|
+
localKeys: number;
|
|
54
|
+
sessionKeys: number;
|
|
55
|
+
}>;
|
|
56
|
+
export declare function clearStorageState(page: Page, scope?: StorageScope): Promise<{
|
|
57
|
+
origin: string;
|
|
58
|
+
scope: StorageScope;
|
|
59
|
+
}>;
|
|
60
|
+
export declare function evaluateExpression(page: Page, expression: string): Promise<EvalResponse["value"]>;
|
|
61
|
+
export declare function annotatePageWithRefs(page: Page, refs: Array<{
|
|
62
|
+
ref: string;
|
|
63
|
+
x: number;
|
|
64
|
+
y: number;
|
|
65
|
+
}>): Promise<void>;
|
|
66
|
+
export declare function clearPageAnnotations(page: Page): Promise<void>;
|
|
67
|
+
export declare function closeSessionHandles(session: SessionRecord): Promise<void>;
|