diff --git a/src/browser/chrome.ts b/src/browser/chrome.ts index 8e0909211..946114421 100644 --- a/src/browser/chrome.ts +++ b/src/browser/chrome.ts @@ -4,8 +4,7 @@ import os from "node:os"; import path from "node:path"; import { ensurePortAvailable } from "../infra/ports.js"; -import { logInfo, logWarn } from "../logger.js"; -import { defaultRuntime, type RuntimeEnv } from "../runtime.js"; +import { createSubsystemLogger } from "../logging.js"; import { CONFIG_DIR } from "../utils.js"; import type { ResolvedBrowserConfig } from "./config.js"; import { @@ -13,6 +12,8 @@ import { DEFAULT_CLAWD_BROWSER_PROFILE_NAME, } from "./constants.js"; +const log = createSubsystemLogger("browser").child("chrome"); + export type BrowserExecutable = { kind: "canary" | "chromium" | "chrome"; path: string; @@ -321,7 +322,6 @@ export async function isChromeReachable( export async function launchClawdChrome( resolved: ResolvedBrowserConfig, - runtime: RuntimeEnv = defaultRuntime, ): Promise { await ensurePortAvailable(resolved.cdpPort); @@ -404,15 +404,9 @@ export async function launchClawdChrome( if (needsDecorate) { try { decorateClawdProfile(userDataDir, { color: resolved.color }); - logInfo( - `🦞 clawd browser profile decorated (${resolved.color})`, - runtime, - ); + log.info(`🦞 clawd browser profile decorated (${resolved.color})`); } catch (err) { - logWarn( - `clawd browser profile decoration failed: ${String(err)}`, - runtime, - ); + log.warn(`clawd browser profile decoration failed: ${String(err)}`); } } @@ -434,9 +428,8 @@ export async function launchClawdChrome( } const pid = proc.pid ?? -1; - logInfo( + log.info( `🦞 clawd browser started (${exe.kind}) on 127.0.0.1:${resolved.cdpPort} (pid ${pid})`, - runtime, ); return { diff --git a/src/browser/server-context.ts b/src/browser/server-context.ts index c95f34406..255eb9127 100644 --- a/src/browser/server-context.ts +++ b/src/browser/server-context.ts @@ -1,6 +1,5 @@ import type { Server } from "node:http"; -import type { RuntimeEnv } from "../runtime.js"; import { createTargetViaCdp } from "./cdp.js"; import { isChromeReachable, @@ -41,7 +40,6 @@ export type BrowserRouteContext = { }; type ContextOptions = { - runtime: RuntimeEnv; getState: () => BrowserServerState | null; setRunning: (running: RunningChrome | null) => void; }; @@ -172,7 +170,7 @@ export function createBrowserRouteContext( ); } - const launched = await launchClawdChrome(current.resolved, opts.runtime); + const launched = await launchClawdChrome(current.resolved); opts.setRunning(launched); launched.proc.on("exit", () => { const live = opts.getState(); diff --git a/src/browser/server.ts b/src/browser/server.ts index 4bf79d6be..f08858e64 100644 --- a/src/browser/server.ts +++ b/src/browser/server.ts @@ -2,8 +2,7 @@ import type { Server } from "node:http"; import express from "express"; import { loadConfig } from "../config/config.js"; -import { logError, logInfo, logWarn } from "../logger.js"; -import { defaultRuntime, type RuntimeEnv } from "../runtime.js"; +import { createSubsystemLogger } from "../logging.js"; import { resolveBrowserConfig, shouldStartLocalBrowserServer, @@ -15,9 +14,10 @@ import { } from "./server-context.js"; let state: BrowserServerState | null = null; +const log = createSubsystemLogger("browser"); +const logServer = log.child("server"); export async function startBrowserControlServerFromConfig( - runtime: RuntimeEnv = defaultRuntime, ): Promise { if (state) return state; @@ -26,9 +26,8 @@ export async function startBrowserControlServerFromConfig( if (!resolved.enabled) return null; if (!shouldStartLocalBrowserServer(resolved)) { - logInfo( + logServer.info( `browser control URL is non-loopback (${resolved.controlUrl}); skipping local server start`, - runtime, ); return null; } @@ -37,7 +36,6 @@ export async function startBrowserControlServerFromConfig( app.use(express.json({ limit: "1mb" })); const ctx = createBrowserRouteContext({ - runtime, getState: () => state, setRunning: (running) => { if (state) state.running = running; @@ -50,9 +48,8 @@ export async function startBrowserControlServerFromConfig( const s = app.listen(port, "127.0.0.1", () => resolve(s)); s.once("error", reject); }).catch((err) => { - logError( + logServer.error( `clawd browser server failed to bind 127.0.0.1:${port}: ${String(err)}`, - runtime, ); return null; }); @@ -67,21 +64,18 @@ export async function startBrowserControlServerFromConfig( resolved, }; - logInfo( + logServer.info( `🦞 clawd browser control listening on http://127.0.0.1:${port}/`, - runtime, ); return state; } export async function stopBrowserControlServer( - runtime: RuntimeEnv = defaultRuntime, ): Promise { const current = state; if (!current) return; const ctx = createBrowserRouteContext({ - runtime, getState: () => state, setRunning: (running) => { if (state) state.running = running; @@ -91,7 +85,7 @@ export async function stopBrowserControlServer( try { await ctx.stopRunningBrowser(); } catch (err) { - logWarn(`clawd browser stop failed: ${String(err)}`, runtime); + logServer.warn(`clawd browser stop failed: ${String(err)}`); } await new Promise((resolve) => {