style: fix lint

This commit is contained in:
Peter Steinberger
2026-01-04 03:37:00 +00:00
parent c2f3b653c2
commit 7d95f43a75
4 changed files with 118 additions and 79 deletions

View File

@@ -8,7 +8,10 @@ import { ensurePortAvailable } from "../infra/ports.js";
import { createSubsystemLogger } from "../logging.js"; import { createSubsystemLogger } from "../logging.js";
import { CONFIG_DIR } from "../utils.js"; import { CONFIG_DIR } from "../utils.js";
import { normalizeCdpWsUrl } from "./cdp.js"; import { normalizeCdpWsUrl } from "./cdp.js";
import type { ResolvedBrowserConfig, ResolvedBrowserProfile } from "./config.js"; import type {
ResolvedBrowserConfig,
ResolvedBrowserProfile,
} from "./config.js";
import { import {
DEFAULT_CLAWD_BROWSER_COLOR, DEFAULT_CLAWD_BROWSER_COLOR,
DEFAULT_CLAWD_BROWSER_PROFILE_NAME, DEFAULT_CLAWD_BROWSER_PROFILE_NAME,
@@ -119,12 +122,7 @@ function resolveBrowserExecutable(
export function resolveClawdUserDataDir( export function resolveClawdUserDataDir(
profileName = DEFAULT_CLAWD_BROWSER_PROFILE_NAME, profileName = DEFAULT_CLAWD_BROWSER_PROFILE_NAME,
) { ) {
return path.join( return path.join(CONFIG_DIR, "browser", profileName, "user-data");
CONFIG_DIR,
"browser",
profileName,
"user-data",
);
} }
function decoratedMarkerPath(userDataDir: string) { function decoratedMarkerPath(userDataDir: string) {

View File

@@ -27,13 +27,10 @@ export async function browserPdfSave(
opts: { targetId?: string; profile?: string } = {}, opts: { targetId?: string; profile?: string } = {},
): Promise<BrowserActionPathResult> { ): Promise<BrowserActionPathResult> {
const q = buildProfileQuery(opts.profile); const q = buildProfileQuery(opts.profile);
return await fetchBrowserJson<BrowserActionPathResult>( return await fetchBrowserJson<BrowserActionPathResult>(`${baseUrl}/pdf${q}`, {
`${baseUrl}/pdf${q}`,
{
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ targetId: opts.targetId }), body: JSON.stringify({ targetId: opts.targetId }),
timeoutMs: 20000, timeoutMs: 20000,
}, });
);
} }

View File

@@ -98,12 +98,16 @@ export function registerBrowserActionInputCommands(
return; return;
} }
try { try {
const result = await browserAct(baseUrl, { const result = await browserAct(
baseUrl,
{
kind: "resize", kind: "resize",
width, width,
height, height,
targetId: opts.targetId?.trim() || undefined, targetId: opts.targetId?.trim() || undefined,
}, { profile }); },
{ profile },
);
if (parent?.json) { if (parent?.json) {
defaultRuntime.log(JSON.stringify(result, null, 2)); defaultRuntime.log(JSON.stringify(result, null, 2));
return; return;
@@ -140,14 +144,18 @@ export function registerBrowserActionInputCommands(
.filter(Boolean) .filter(Boolean)
: undefined; : undefined;
try { try {
const result = await browserAct(baseUrl, { const result = await browserAct(
baseUrl,
{
kind: "click", kind: "click",
ref: refValue, ref: refValue,
targetId: opts.targetId?.trim() || undefined, targetId: opts.targetId?.trim() || undefined,
doubleClick: Boolean(opts.double), doubleClick: Boolean(opts.double),
button: opts.button?.trim() || undefined, button: opts.button?.trim() || undefined,
modifiers, modifiers,
}, { profile }); },
{ profile },
);
if (parent?.json) { if (parent?.json) {
defaultRuntime.log(JSON.stringify(result, null, 2)); defaultRuntime.log(JSON.stringify(result, null, 2));
return; return;
@@ -179,14 +187,18 @@ export function registerBrowserActionInputCommands(
return; return;
} }
try { try {
const result = await browserAct(baseUrl, { const result = await browserAct(
baseUrl,
{
kind: "type", kind: "type",
ref: refValue, ref: refValue,
text, text,
submit: Boolean(opts.submit), submit: Boolean(opts.submit),
slowly: Boolean(opts.slowly), slowly: Boolean(opts.slowly),
targetId: opts.targetId?.trim() || undefined, targetId: opts.targetId?.trim() || undefined,
}, { profile }); },
{ profile },
);
if (parent?.json) { if (parent?.json) {
defaultRuntime.log(JSON.stringify(result, null, 2)); defaultRuntime.log(JSON.stringify(result, null, 2));
return; return;
@@ -208,11 +220,15 @@ export function registerBrowserActionInputCommands(
const baseUrl = resolveBrowserControlUrl(parent?.url); const baseUrl = resolveBrowserControlUrl(parent?.url);
const profile = parent?.profile; const profile = parent?.profile;
try { try {
const result = await browserAct(baseUrl, { const result = await browserAct(
baseUrl,
{
kind: "press", kind: "press",
key, key,
targetId: opts.targetId?.trim() || undefined, targetId: opts.targetId?.trim() || undefined,
}, { profile }); },
{ profile },
);
if (parent?.json) { if (parent?.json) {
defaultRuntime.log(JSON.stringify(result, null, 2)); defaultRuntime.log(JSON.stringify(result, null, 2));
return; return;
@@ -234,11 +250,15 @@ export function registerBrowserActionInputCommands(
const baseUrl = resolveBrowserControlUrl(parent?.url); const baseUrl = resolveBrowserControlUrl(parent?.url);
const profile = parent?.profile; const profile = parent?.profile;
try { try {
const result = await browserAct(baseUrl, { const result = await browserAct(
baseUrl,
{
kind: "hover", kind: "hover",
ref, ref,
targetId: opts.targetId?.trim() || undefined, targetId: opts.targetId?.trim() || undefined,
}, { profile }); },
{ profile },
);
if (parent?.json) { if (parent?.json) {
defaultRuntime.log(JSON.stringify(result, null, 2)); defaultRuntime.log(JSON.stringify(result, null, 2));
return; return;
@@ -261,12 +281,16 @@ export function registerBrowserActionInputCommands(
const baseUrl = resolveBrowserControlUrl(parent?.url); const baseUrl = resolveBrowserControlUrl(parent?.url);
const profile = parent?.profile; const profile = parent?.profile;
try { try {
const result = await browserAct(baseUrl, { const result = await browserAct(
baseUrl,
{
kind: "drag", kind: "drag",
startRef, startRef,
endRef, endRef,
targetId: opts.targetId?.trim() || undefined, targetId: opts.targetId?.trim() || undefined,
}, { profile }); },
{ profile },
);
if (parent?.json) { if (parent?.json) {
defaultRuntime.log(JSON.stringify(result, null, 2)); defaultRuntime.log(JSON.stringify(result, null, 2));
return; return;
@@ -289,12 +313,16 @@ export function registerBrowserActionInputCommands(
const baseUrl = resolveBrowserControlUrl(parent?.url); const baseUrl = resolveBrowserControlUrl(parent?.url);
const profile = parent?.profile; const profile = parent?.profile;
try { try {
const result = await browserAct(baseUrl, { const result = await browserAct(
baseUrl,
{
kind: "select", kind: "select",
ref, ref,
values, values,
targetId: opts.targetId?.trim() || undefined, targetId: opts.targetId?.trim() || undefined,
}, { profile }); },
{ profile },
);
if (parent?.json) { if (parent?.json) {
defaultRuntime.log(JSON.stringify(result, null, 2)); defaultRuntime.log(JSON.stringify(result, null, 2));
return; return;
@@ -361,11 +389,15 @@ export function registerBrowserActionInputCommands(
fields: opts.fields, fields: opts.fields,
fieldsFile: opts.fieldsFile, fieldsFile: opts.fieldsFile,
}); });
const result = await browserAct(baseUrl, { const result = await browserAct(
baseUrl,
{
kind: "fill", kind: "fill",
fields, fields,
targetId: opts.targetId?.trim() || undefined, targetId: opts.targetId?.trim() || undefined,
}, { profile }); },
{ profile },
);
if (parent?.json) { if (parent?.json) {
defaultRuntime.log(JSON.stringify(result, null, 2)); defaultRuntime.log(JSON.stringify(result, null, 2));
return; return;
@@ -432,13 +464,17 @@ export function registerBrowserActionInputCommands(
const baseUrl = resolveBrowserControlUrl(parent?.url); const baseUrl = resolveBrowserControlUrl(parent?.url);
const profile = parent?.profile; const profile = parent?.profile;
try { try {
const result = await browserAct(baseUrl, { const result = await browserAct(
baseUrl,
{
kind: "wait", kind: "wait",
timeMs: Number.isFinite(opts.time) ? opts.time : undefined, timeMs: Number.isFinite(opts.time) ? opts.time : undefined,
text: opts.text?.trim() || undefined, text: opts.text?.trim() || undefined,
textGone: opts.textGone?.trim() || undefined, textGone: opts.textGone?.trim() || undefined,
targetId: opts.targetId?.trim() || undefined, targetId: opts.targetId?.trim() || undefined,
}, { profile }); },
{ profile },
);
if (parent?.json) { if (parent?.json) {
defaultRuntime.log(JSON.stringify(result, null, 2)); defaultRuntime.log(JSON.stringify(result, null, 2));
return; return;
@@ -466,12 +502,16 @@ export function registerBrowserActionInputCommands(
return; return;
} }
try { try {
const result = await browserAct(baseUrl, { const result = await browserAct(
baseUrl,
{
kind: "evaluate", kind: "evaluate",
fn: opts.fn, fn: opts.fn,
ref: opts.ref?.trim() || undefined, ref: opts.ref?.trim() || undefined,
targetId: opts.targetId?.trim() || undefined, targetId: opts.targetId?.trim() || undefined,
}, { profile }); },
{ profile },
);
if (parent?.json) { if (parent?.json) {
defaultRuntime.log(JSON.stringify(result, null, 2)); defaultRuntime.log(JSON.stringify(result, null, 2));
return; return;

View File

@@ -1 +1,5 @@
export type BrowserParentOpts = { url?: string; json?: boolean; profile?: string }; export type BrowserParentOpts = {
url?: string;
json?: boolean;
profile?: string;
};