refactor: route browser control via gateway/node
This commit is contained in:
@@ -1,16 +1,8 @@
|
||||
import type { Command } from "commander";
|
||||
|
||||
import { resolveBrowserControlUrl } from "../browser/client.js";
|
||||
import {
|
||||
browserHighlight,
|
||||
browserPageErrors,
|
||||
browserRequests,
|
||||
browserTraceStart,
|
||||
browserTraceStop,
|
||||
} from "../browser/client-actions.js";
|
||||
import { danger } from "../globals.js";
|
||||
import { defaultRuntime } from "../runtime.js";
|
||||
import type { BrowserParentOpts } from "./browser-cli-shared.js";
|
||||
import { callBrowserRequest, type BrowserParentOpts } from "./browser-cli-shared.js";
|
||||
import { runCommandWithRuntime } from "./cli-utils.js";
|
||||
import { shortenHomePath } from "../utils.js";
|
||||
|
||||
@@ -32,14 +24,21 @@ export function registerBrowserDebugCommands(
|
||||
.option("--target-id <id>", "CDP target id (or unique prefix)")
|
||||
.action(async (ref: string, opts, cmd) => {
|
||||
const parent = parentOpts(cmd);
|
||||
const baseUrl = resolveBrowserControlUrl(parent?.url);
|
||||
const profile = parent?.browserProfile;
|
||||
await runBrowserDebug(async () => {
|
||||
const result = await browserHighlight(baseUrl, {
|
||||
ref: ref.trim(),
|
||||
targetId: opts.targetId?.trim() || undefined,
|
||||
profile,
|
||||
});
|
||||
const result = await callBrowserRequest(
|
||||
parent,
|
||||
{
|
||||
method: "POST",
|
||||
path: "/highlight",
|
||||
query: profile ? { profile } : undefined,
|
||||
body: {
|
||||
ref: ref.trim(),
|
||||
targetId: opts.targetId?.trim() || undefined,
|
||||
},
|
||||
},
|
||||
{ timeoutMs: 20000 },
|
||||
);
|
||||
if (parent?.json) {
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
return;
|
||||
@@ -55,14 +54,23 @@ export function registerBrowserDebugCommands(
|
||||
.option("--target-id <id>", "CDP target id (or unique prefix)")
|
||||
.action(async (opts, cmd) => {
|
||||
const parent = parentOpts(cmd);
|
||||
const baseUrl = resolveBrowserControlUrl(parent?.url);
|
||||
const profile = parent?.browserProfile;
|
||||
await runBrowserDebug(async () => {
|
||||
const result = await browserPageErrors(baseUrl, {
|
||||
targetId: opts.targetId?.trim() || undefined,
|
||||
clear: Boolean(opts.clear),
|
||||
profile,
|
||||
});
|
||||
const result = await callBrowserRequest<{
|
||||
errors: Array<{ timestamp: string; name?: string; message: string }>;
|
||||
}>(
|
||||
parent,
|
||||
{
|
||||
method: "GET",
|
||||
path: "/errors",
|
||||
query: {
|
||||
targetId: opts.targetId?.trim() || undefined,
|
||||
clear: Boolean(opts.clear),
|
||||
profile,
|
||||
},
|
||||
},
|
||||
{ timeoutMs: 20000 },
|
||||
);
|
||||
if (parent?.json) {
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
return;
|
||||
@@ -87,15 +95,31 @@ export function registerBrowserDebugCommands(
|
||||
.option("--target-id <id>", "CDP target id (or unique prefix)")
|
||||
.action(async (opts, cmd) => {
|
||||
const parent = parentOpts(cmd);
|
||||
const baseUrl = resolveBrowserControlUrl(parent?.url);
|
||||
const profile = parent?.browserProfile;
|
||||
await runBrowserDebug(async () => {
|
||||
const result = await browserRequests(baseUrl, {
|
||||
targetId: opts.targetId?.trim() || undefined,
|
||||
filter: opts.filter?.trim() || undefined,
|
||||
clear: Boolean(opts.clear),
|
||||
profile,
|
||||
});
|
||||
const result = await callBrowserRequest<{
|
||||
requests: Array<{
|
||||
timestamp: string;
|
||||
method: string;
|
||||
status?: number;
|
||||
ok?: boolean;
|
||||
url: string;
|
||||
failureText?: string;
|
||||
}>;
|
||||
}>(
|
||||
parent,
|
||||
{
|
||||
method: "GET",
|
||||
path: "/requests",
|
||||
query: {
|
||||
targetId: opts.targetId?.trim() || undefined,
|
||||
filter: opts.filter?.trim() || undefined,
|
||||
clear: Boolean(opts.clear),
|
||||
profile,
|
||||
},
|
||||
},
|
||||
{ timeoutMs: 20000 },
|
||||
);
|
||||
if (parent?.json) {
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
return;
|
||||
@@ -128,16 +152,23 @@ export function registerBrowserDebugCommands(
|
||||
.option("--sources", "Include sources (bigger traces)", false)
|
||||
.action(async (opts, cmd) => {
|
||||
const parent = parentOpts(cmd);
|
||||
const baseUrl = resolveBrowserControlUrl(parent?.url);
|
||||
const profile = parent?.browserProfile;
|
||||
await runBrowserDebug(async () => {
|
||||
const result = await browserTraceStart(baseUrl, {
|
||||
targetId: opts.targetId?.trim() || undefined,
|
||||
screenshots: Boolean(opts.screenshots),
|
||||
snapshots: Boolean(opts.snapshots),
|
||||
sources: Boolean(opts.sources),
|
||||
profile,
|
||||
});
|
||||
const result = await callBrowserRequest(
|
||||
parent,
|
||||
{
|
||||
method: "POST",
|
||||
path: "/trace/start",
|
||||
query: profile ? { profile } : undefined,
|
||||
body: {
|
||||
targetId: opts.targetId?.trim() || undefined,
|
||||
screenshots: Boolean(opts.screenshots),
|
||||
snapshots: Boolean(opts.snapshots),
|
||||
sources: Boolean(opts.sources),
|
||||
},
|
||||
},
|
||||
{ timeoutMs: 20000 },
|
||||
);
|
||||
if (parent?.json) {
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
return;
|
||||
@@ -153,14 +184,21 @@ export function registerBrowserDebugCommands(
|
||||
.option("--target-id <id>", "CDP target id (or unique prefix)")
|
||||
.action(async (opts, cmd) => {
|
||||
const parent = parentOpts(cmd);
|
||||
const baseUrl = resolveBrowserControlUrl(parent?.url);
|
||||
const profile = parent?.browserProfile;
|
||||
await runBrowserDebug(async () => {
|
||||
const result = await browserTraceStop(baseUrl, {
|
||||
targetId: opts.targetId?.trim() || undefined,
|
||||
path: opts.out?.trim() || undefined,
|
||||
profile,
|
||||
});
|
||||
const result = await callBrowserRequest<{ path: string }>(
|
||||
parent,
|
||||
{
|
||||
method: "POST",
|
||||
path: "/trace/stop",
|
||||
query: profile ? { profile } : undefined,
|
||||
body: {
|
||||
targetId: opts.targetId?.trim() || undefined,
|
||||
path: opts.out?.trim() || undefined,
|
||||
},
|
||||
},
|
||||
{ timeoutMs: 20000 },
|
||||
);
|
||||
if (parent?.json) {
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user