browser

tcmts.cli.browser.browser · #547plj62 · function · runs on the server

uses node:child_process

tcm browser <agent-browser arguments…>: agent-browser, run with them as given (open app.App as browserArgs says), on the Chrome tcm shot uses unless AGENT_BROWSER_EXECUTABLE_PATH says (with none, agent-browser's own, from its install), in the codebase branch's own session unless AGENT_BROWSER_SESSION or --session says. What it prints, and its exit code.

import { agentBrowserBin, browserArgs, browserSession, chromePath, workingBranch } from "#codebase/tcmts/cli/browser";
import { Codebase } from "#codebase/tcmts/cli/codebase";
import { spawnSync } from "node:child_process";

export async function browser({ cwd, args }: { cwd: string; args: string[] }): Promise<number> {
  let root: string | undefined;
  try {
    root = Codebase.findRoot(cwd);
  } catch {
    root = undefined;
  }
  const argv = browserArgs(args, root);
  const env = { ...process.env };
  if (
    !env.AGENT_BROWSER_SESSION &&
    !args.some((a) => a === "--session" || a.startsWith("--session="))
  )
    env.AGENT_BROWSER_SESSION = browserSession(root, root && workingBranch(root), cwd);
  if (!env.AGENT_BROWSER_EXECUTABLE_PATH) {
    const chrome = await chromePath();
    if (chrome) env.AGENT_BROWSER_EXECUTABLE_PATH = chrome;
  }
  const bin = agentBrowserBin();
  const r = spawnSync(process.execPath, [bin, ...argv], { cwd, env, stdio: "inherit" });
  if (r.error) throw r.error;
  return r.status ?? 1;
}

uses

used by