style: fix lint
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
@@ -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",
|
||||||
{
|
headers: { "Content-Type": "application/json" },
|
||||||
method: "POST",
|
body: JSON.stringify({ targetId: opts.targetId }),
|
||||||
headers: { "Content-Type": "application/json" },
|
timeoutMs: 20000,
|
||||||
body: JSON.stringify({ targetId: opts.targetId }),
|
});
|
||||||
timeoutMs: 20000,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,12 +98,16 @@ export function registerBrowserActionInputCommands(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const result = await browserAct(baseUrl, {
|
const result = await browserAct(
|
||||||
kind: "resize",
|
baseUrl,
|
||||||
width,
|
{
|
||||||
height,
|
kind: "resize",
|
||||||
targetId: opts.targetId?.trim() || undefined,
|
width,
|
||||||
}, { profile });
|
height,
|
||||||
|
targetId: opts.targetId?.trim() || undefined,
|
||||||
|
},
|
||||||
|
{ 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(
|
||||||
kind: "click",
|
baseUrl,
|
||||||
ref: refValue,
|
{
|
||||||
targetId: opts.targetId?.trim() || undefined,
|
kind: "click",
|
||||||
doubleClick: Boolean(opts.double),
|
ref: refValue,
|
||||||
button: opts.button?.trim() || undefined,
|
targetId: opts.targetId?.trim() || undefined,
|
||||||
modifiers,
|
doubleClick: Boolean(opts.double),
|
||||||
}, { profile });
|
button: opts.button?.trim() || undefined,
|
||||||
|
modifiers,
|
||||||
|
},
|
||||||
|
{ 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(
|
||||||
kind: "type",
|
baseUrl,
|
||||||
ref: refValue,
|
{
|
||||||
text,
|
kind: "type",
|
||||||
submit: Boolean(opts.submit),
|
ref: refValue,
|
||||||
slowly: Boolean(opts.slowly),
|
text,
|
||||||
targetId: opts.targetId?.trim() || undefined,
|
submit: Boolean(opts.submit),
|
||||||
}, { profile });
|
slowly: Boolean(opts.slowly),
|
||||||
|
targetId: opts.targetId?.trim() || undefined,
|
||||||
|
},
|
||||||
|
{ 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(
|
||||||
kind: "press",
|
baseUrl,
|
||||||
key,
|
{
|
||||||
targetId: opts.targetId?.trim() || undefined,
|
kind: "press",
|
||||||
}, { profile });
|
key,
|
||||||
|
targetId: opts.targetId?.trim() || undefined,
|
||||||
|
},
|
||||||
|
{ 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(
|
||||||
kind: "hover",
|
baseUrl,
|
||||||
ref,
|
{
|
||||||
targetId: opts.targetId?.trim() || undefined,
|
kind: "hover",
|
||||||
}, { profile });
|
ref,
|
||||||
|
targetId: opts.targetId?.trim() || undefined,
|
||||||
|
},
|
||||||
|
{ 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(
|
||||||
kind: "drag",
|
baseUrl,
|
||||||
startRef,
|
{
|
||||||
endRef,
|
kind: "drag",
|
||||||
targetId: opts.targetId?.trim() || undefined,
|
startRef,
|
||||||
}, { profile });
|
endRef,
|
||||||
|
targetId: opts.targetId?.trim() || undefined,
|
||||||
|
},
|
||||||
|
{ 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(
|
||||||
kind: "select",
|
baseUrl,
|
||||||
ref,
|
{
|
||||||
values,
|
kind: "select",
|
||||||
targetId: opts.targetId?.trim() || undefined,
|
ref,
|
||||||
}, { profile });
|
values,
|
||||||
|
targetId: opts.targetId?.trim() || undefined,
|
||||||
|
},
|
||||||
|
{ 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(
|
||||||
kind: "fill",
|
baseUrl,
|
||||||
fields,
|
{
|
||||||
targetId: opts.targetId?.trim() || undefined,
|
kind: "fill",
|
||||||
}, { profile });
|
fields,
|
||||||
|
targetId: opts.targetId?.trim() || undefined,
|
||||||
|
},
|
||||||
|
{ 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(
|
||||||
kind: "wait",
|
baseUrl,
|
||||||
timeMs: Number.isFinite(opts.time) ? opts.time : undefined,
|
{
|
||||||
text: opts.text?.trim() || undefined,
|
kind: "wait",
|
||||||
textGone: opts.textGone?.trim() || undefined,
|
timeMs: Number.isFinite(opts.time) ? opts.time : undefined,
|
||||||
targetId: opts.targetId?.trim() || undefined,
|
text: opts.text?.trim() || undefined,
|
||||||
}, { profile });
|
textGone: opts.textGone?.trim() || undefined,
|
||||||
|
targetId: opts.targetId?.trim() || undefined,
|
||||||
|
},
|
||||||
|
{ 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(
|
||||||
kind: "evaluate",
|
baseUrl,
|
||||||
fn: opts.fn,
|
{
|
||||||
ref: opts.ref?.trim() || undefined,
|
kind: "evaluate",
|
||||||
targetId: opts.targetId?.trim() || undefined,
|
fn: opts.fn,
|
||||||
}, { profile });
|
ref: opts.ref?.trim() || undefined,
|
||||||
|
targetId: opts.targetId?.trim() || undefined,
|
||||||
|
},
|
||||||
|
{ profile },
|
||||||
|
);
|
||||||
if (parent?.json) {
|
if (parent?.json) {
|
||||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1 +1,5 @@
|
|||||||
export type BrowserParentOpts = { url?: string; json?: boolean; profile?: string };
|
export type BrowserParentOpts = {
|
||||||
|
url?: string;
|
||||||
|
json?: boolean;
|
||||||
|
profile?: string;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user