refactor(browser): split pw tools + agent routes

This commit is contained in:
Peter Steinberger
2026-01-14 05:39:44 +00:00
parent da6f07b7c1
commit 2b60ee96f2
27 changed files with 2781 additions and 2633 deletions

View File

@@ -0,0 +1,39 @@
import { ensureContextState, getPageForTargetId } from "./pw-session.js";
export async function traceStartViaPlaywright(opts: {
cdpUrl: string;
targetId?: string;
screenshots?: boolean;
snapshots?: boolean;
sources?: boolean;
}): Promise<void> {
const page = await getPageForTargetId(opts);
const context = page.context();
const ctxState = ensureContextState(context);
if (ctxState.traceActive) {
throw new Error(
"Trace already running. Stop the current trace before starting a new one.",
);
}
await context.tracing.start({
screenshots: opts.screenshots ?? true,
snapshots: opts.snapshots ?? true,
sources: opts.sources ?? false,
});
ctxState.traceActive = true;
}
export async function traceStopViaPlaywright(opts: {
cdpUrl: string;
targetId?: string;
path: string;
}): Promise<void> {
const page = await getPageForTargetId(opts);
const context = page.context();
const ctxState = ensureContextState(context);
if (!ctxState.traceActive) {
throw new Error("No active trace. Start a trace before stopping it.");
}
await context.tracing.stop({ path: opts.path });
ctxState.traceActive = false;
}