feat(browser_list): añade campo headless por master

browser_list ahora reporta si cada Chromium master se lanzo en modo headless,
detectado por el flag de arranque (--headless / --headless=new / --headless=old)
leido del cmdline. Una sola llamada devuelve navegadores activos + CDP + headless,
sin tener que conectar a cada pagina para fingerprintear.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Egutierrez
2026-06-16 20:05:51 +02:00
parent c56004da5c
commit 91973ed6f9
2 changed files with 44 additions and 1 deletions
+16 -1
View File
@@ -55,6 +55,7 @@ type chromiumMaster struct {
UserDataDir string `json:"user_data_dir"` // value of --user-data-dir
CDPPort string `json:"cdp_port"` // value of --remote-debugging-port ("" if none)
HasCDP bool `json:"has_cdp"`
Headless bool `json:"headless"` // true if launched with --headless / --headless=new / --headless=old
}
// parseCmdline turns the raw bytes of /proc/<pid>/cmdline into argv.
@@ -154,9 +155,23 @@ func parseChromiumMaster(pid int, args []string) (chromiumMaster, bool) {
UserDataDir: udd,
CDPPort: port,
HasCDP: hasCDP,
Headless: isHeadless(args),
}, true
}
// isHeadless reports whether the process was launched in headless mode. Chromium
// spells it "--headless", "--headless=new" or "--headless=old"; matching the
// "--headless" prefix covers all three. There is no current Chromium flag that
// starts with "--headless" but means something else, so the prefix is safe.
func isHeadless(args []string) bool {
for _, a := range args {
if a == "--headless" || strings.HasPrefix(a, "--headless=") {
return true
}
}
return false
}
// firstNonEmpty returns the flag value or "" if absent.
func firstNonEmpty(args []string, name string) string {
v, _ := flagValue(args, name)
@@ -256,7 +271,7 @@ type browserListArgs struct{}
func browserListTool() mcp.Tool {
return mcp.NewTool("browser_list",
mcp.WithDescription("List the running Chromium MASTER processes (one per user-data-dir master, NOT zygote/gpu/renderer children). For each: pid, profile (--profile-directory value), user_data_dir, cdp_port (--remote-debugging-port value, empty if none), has_cdp. Returns a JSON array. Read-only."),
mcp.WithDescription("List the running Chromium MASTER processes (one per user-data-dir master, NOT zygote/gpu/renderer children). For each: pid, profile (--profile-directory value), user_data_dir, cdp_port (--remote-debugging-port value, empty if none), has_cdp, headless (true if launched with --headless). Returns a JSON array. Read-only."),
)
}