refactor(browser): trim observe endpoints
This commit is contained in:
@@ -2,14 +2,10 @@ import type { Command } from "commander";
|
||||
import { resolveBrowserControlUrl } from "../browser/client.js";
|
||||
import {
|
||||
browserConsoleMessages,
|
||||
browserGenerateLocator,
|
||||
browserMouseClick,
|
||||
browserMouseDrag,
|
||||
browserMouseMove,
|
||||
browserNetworkRequests,
|
||||
browserPdfSave,
|
||||
browserStartTracing,
|
||||
browserStopTracing,
|
||||
browserVerifyElementVisible,
|
||||
browserVerifyListVisible,
|
||||
browserVerifyTextVisible,
|
||||
@@ -47,74 +43,6 @@ export function registerBrowserActionObserveCommands(
|
||||
}
|
||||
});
|
||||
|
||||
browser
|
||||
.command("network")
|
||||
.description("Get recent network requests")
|
||||
.option("--include-static", "Include static assets", false)
|
||||
.option("--target-id <id>", "CDP target id (or unique prefix)")
|
||||
.action(async (opts, cmd) => {
|
||||
const parent = parentOpts(cmd);
|
||||
const baseUrl = resolveBrowserControlUrl(parent?.url);
|
||||
try {
|
||||
const result = await browserNetworkRequests(baseUrl, {
|
||||
includeStatic: Boolean(opts.includeStatic),
|
||||
targetId: opts.targetId?.trim() || undefined,
|
||||
});
|
||||
if (parent?.json) {
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
return;
|
||||
}
|
||||
defaultRuntime.log(JSON.stringify(result.requests, null, 2));
|
||||
} catch (err) {
|
||||
defaultRuntime.error(danger(String(err)));
|
||||
defaultRuntime.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
browser
|
||||
.command("trace-start")
|
||||
.description("Start Playwright tracing")
|
||||
.option("--target-id <id>", "CDP target id (or unique prefix)")
|
||||
.action(async (opts, cmd) => {
|
||||
const parent = parentOpts(cmd);
|
||||
const baseUrl = resolveBrowserControlUrl(parent?.url);
|
||||
try {
|
||||
const result = await browserStartTracing(baseUrl, {
|
||||
targetId: opts.targetId?.trim() || undefined,
|
||||
});
|
||||
if (parent?.json) {
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
return;
|
||||
}
|
||||
defaultRuntime.log("trace started");
|
||||
} catch (err) {
|
||||
defaultRuntime.error(danger(String(err)));
|
||||
defaultRuntime.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
browser
|
||||
.command("trace-stop")
|
||||
.description("Stop tracing and save a trace.zip")
|
||||
.option("--target-id <id>", "CDP target id (or unique prefix)")
|
||||
.action(async (opts, cmd) => {
|
||||
const parent = parentOpts(cmd);
|
||||
const baseUrl = resolveBrowserControlUrl(parent?.url);
|
||||
try {
|
||||
const result = await browserStopTracing(baseUrl, {
|
||||
targetId: opts.targetId?.trim() || undefined,
|
||||
});
|
||||
if (parent?.json) {
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
return;
|
||||
}
|
||||
defaultRuntime.log(`trace: ${result.path}`);
|
||||
} catch (err) {
|
||||
defaultRuntime.error(danger(String(err)));
|
||||
defaultRuntime.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
browser
|
||||
.command("pdf")
|
||||
.description("Save page as PDF")
|
||||
@@ -356,24 +284,4 @@ export function registerBrowserActionObserveCommands(
|
||||
defaultRuntime.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
browser
|
||||
.command("locator")
|
||||
.description("Generate a Playwright locator for a ref")
|
||||
.argument("<ref>", "Ref id from ai snapshot")
|
||||
.action(async (ref: string, cmd) => {
|
||||
const parent = parentOpts(cmd);
|
||||
const baseUrl = resolveBrowserControlUrl(parent?.url);
|
||||
try {
|
||||
const result = await browserGenerateLocator(baseUrl, { ref });
|
||||
if (parent?.json) {
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
return;
|
||||
}
|
||||
defaultRuntime.log(result.locator);
|
||||
} catch (err) {
|
||||
defaultRuntime.error(danger(String(err)));
|
||||
defaultRuntime.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -33,9 +33,6 @@ export const browserActionExamples = [
|
||||
"clawdis browser evaluate --fn '(el) => el.textContent' --ref 7",
|
||||
"clawdis browser run --code '(page) => page.title()'",
|
||||
"clawdis browser console --level error",
|
||||
"clawdis browser network --include-static",
|
||||
"clawdis browser trace-start",
|
||||
"clawdis browser trace-stop",
|
||||
"clawdis browser pdf",
|
||||
'clawdis browser verify-element --role button --name "Submit"',
|
||||
'clawdis browser verify-text "Welcome"',
|
||||
@@ -44,5 +41,4 @@ export const browserActionExamples = [
|
||||
"clawdis browser mouse-move --x 120 --y 240",
|
||||
"clawdis browser mouse-click --x 120 --y 240",
|
||||
"clawdis browser mouse-drag --start-x 10 --start-y 20 --end-x 200 --end-y 300",
|
||||
"clawdis browser locator 77",
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user