High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
feat: support loading Chrome extensions in headless instances
Luigi Agostied37b8282334
diff --git a/cmd/pinchtab/cmd_cli.go b/cmd/pinchtab/cmd_cli.goindex b9358f1e..ae90fe01 100644--- a/cmd/pinchtab/cmd_cli.go+++ b/cmd/pinchtab/cmd_cli.go@@ -422,6 +422,7 @@ func init() {startInstanceCmd.Flags().String("profile", "", "Profile to use")startInstanceCmd.Flags().String("mode", "", "Instance mode")startInstanceCmd.Flags().String("port", "", "Port number")+ startInstanceCmd.Flags().StringArray("extension", nil, "Load browser extension (repeatable)")instanceCmd.AddCommand(startInstanceCmd)instanceCmd.AddCommand(&cobra.Command{diff --git a/cmd/pinchtab/cmd_server.go b/cmd/pinchtab/cmd_server.goindex 8eaa028a..1689c2f5 100644--- a/cmd/pinchtab/cmd_server.go+++ b/cmd/pinchtab/cmd_server.go@@ -12,11 +12,15 @@ var serverCmd = &cobra.Command{Run: func(cmd *cobra.Command, args []string) {maybeRunWizard()cfg := config.Load()+ if exts, _ := cmd.Flags().GetStringArray("extension"); len(exts) > 0 {+ cfg.ExtensionPaths = append(cfg.ExtensionPaths, exts...)+ }server.RunDashboard(cfg, version)},}func init() {serverCmd.GroupID = "primary"+ serverCmd.Flags().StringArray("extension", nil, "Load browser extension (repeatable)")rootCmd.AddCommand(serverCmd)}diff --git a/docs/commands.md b/docs/commands.mdindex e8d72969..034ea741 100644--- a/docs/commands.md+++ b/docs/commands.md@@ -4,6 +4,7 @@```pinchtab server # Start the full server (dashboard + API)+pinchtab server --extension /path/to/ext # Start with extension (repeatable)pinchtab bridge # Start bridge-only server (no dashboard)pinchtab mcp # Start the MCP stdio serverpinchtab daemon # Show daemon status@@ -99,6 +100,7 @@ pinchtab instances # List running instancespinchtab instance start # Start a new browser instancepinchtab instance start --profile <name> # Start with specific profilepinchtab instance start --port <n> # Start on specific port+pinchtab instance start --extension /path/to/ext # Load extension (repeatable)pinchtab instance stop <id> # Stop an instancepinchtab instance logs <id> # View instance logspinchtab instance navigate <id> <url> # Navigate instance to URLdiff --git a/internal/bridge/init.go b/internal/bridge/init.goindex 85268418..694e66e7 100644--- a/internal/bridge/init.go+++ b/internal/bridge/init.go@@ -25,14 +25,11 @@ import ()// InitChrome initializes a Chrome browser for a Bridge instance-// It allocates the browser, starts it with appropriate flags (headless/headed),-// and returns the contexts ready for use.func InitChrome(cfg *config.RuntimeConfig) (context.Context, context.CancelFunc, context.Context, context.CancelFunc, error) {slog.Info("starting chrome initialization", "headless", cfg.Headless, "profile", cfg.ProfileDir, "binary", cfg.ChromeBinary)// Setup allocatorallocCtx, allocCancel, opts, debugPort := setupAllocator(cfg)- slog.Debug("chrome allocator configured", "headless", cfg.Headless, "debug_port", debugPort)// Start Chrome browserbrowserCtx, browserCancel, err := startChrome(allocCtx, cfg, opts, debugPort)@@ -46,33 +43,23 @@ func InitChrome(cfg *config.RuntimeConfig) (context.Context, context.CancelFunc,return allocCtx, allocCancel, browserCtx, browserCancel, nil}-// findChromeBinary searches for Chrome in common installation locations-// On ARM64 (Raspberry Pi, etc.), prioritizes chromium-browser for optimal compatibilityfunc findChromeBinary() string {var candidates []string-- // ARM64-specific optimization: Chromium is the standard on Raspberry Piif runtime.GOARCH == "arm64" || runtime.GOARCH == "arm" {candidates = []string{- // ARM64/Raspberry Pi - prioritize chromium-browser"/usr/bin/chromium-browser","/usr/bin/chromium","/usr/bin/google-chrome","/usr/bin/google-chrome-stable",}- slog.Debug("detected ARM architecture, prioritizing chromium-browser", "arch", runtime.GOARCH)} else {- // x86/x64 - standard ordercandidates = []string{- // macOS"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome","/Applications/Chromium.app/Contents/MacOS/Chromium",- // Linux"/usr/bin/google-chrome","/usr/bin/google-chrome-stable","/usr/bin/chromium","/usr/bin/chromium-browser",- // Windows (via WSL or MSYS)"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe","C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",}@@ -80,249 +67,159 @@ func findChromeBinary() string {for _, path := range candidates {if _, err := os.Stat(path); err == nil {- slog.Debug("found chrome binary", "path", path, "arch", runtime.GOARCH)return path}}-- slog.Debug("no chrome binary found in common locations", "arch", runtime.GOARCH)return ""}-// setupAllocator creates a Chrome allocator with appropriate options.-// It returns the allocator context, its cancel function, options, and the-// fixed debug port chosen from the configured range (0 if unavailable).-// Using a fixed port (instead of --remote-debugging-port=0) enables the-// direct-launch fallback for Chrome 145+, which stopped announcing the-// DevTools URL via stderr.+func appendExecAllocatorFlag(opts []chromedp.ExecAllocatorOption, flag string) []chromedp.ExecAllocatorOption {+ name := strings.TrimPrefix(flag, "--")+ if parts := strings.SplitN(name, "=", 2); len(parts) == 2 {+ return append(opts, chromedp.Flag(parts[0], parts[1]))+ }+ return append(opts, chromedp.Flag(name, true))+}+func setupAllocator(cfg *config.RuntimeConfig) (context.Context, context.CancelFunc, []chromedp.ExecAllocatorOption, int) {- opts := chromedp.DefaultExecAllocatorOptions[:]+ opts := []chromedp.ExecAllocatorOption{+ chromedp.NoFirstRun,+ chromedp.NoDefaultBrowserCheck,+ }+ for _, flag := range defaultChromeFlagArgs() {+ opts = appendExecAllocatorFlag(opts, flag)+ }- // Determine Chrome binary path+ // Binary pathchromeBinary := cfg.ChromeBinaryif chromeBinary == "" {- // Try to auto-detect ChromechromeBinary = findChromeBinary()- if chromeBinary != "" {- slog.Info("auto-detected chrome binary", "path", chromeBinary)- }+ }+ if chromeBinary != "" {+ opts = append(opts, chromedp.ExecPath(chromeBinary))}- // Log configuration- slog.Debug("configuring chrome allocator", "headless", cfg.Headless, "binary", chromeBinary, "profile_dir", cfg.ProfileDir)-- // Headless mode+ // Headless mode: always use 'new' for extension supportif cfg.Headless {- opts = append(opts, chromedp.Headless)- slog.Debug("chrome mode set to headless")+ opts = append(opts, chromedp.Flag("headless", "new"))+ opts = append(opts, chromedp.Flag("hide-scrollbars", true))+ opts = append(opts, chromedp.Flag("mute-audio", true))+ opts = append(opts, chromedp.DisableGPU)} else {opts = append(opts, chromedp.Flag("headless", false))- slog.Debug("chrome mode set to headed (visible window)")}- // Chrome binary- if chromeBinary != "" {- opts = append(opts, chromedp.ExecPath(chromeBinary))- slog.Debug("chrome binary path configured", "path", chromeBinary)+ // Extensions+ if len(cfg.ExtensionPaths) > 0 {+ var validPaths []string+ for _, path := range cfg.ExtensionPaths {+ if _, err := os.Stat(path); err == nil {+ validPaths = append(validPaths, path)+ }+ }+ if len(validPaths) > 0 {+ joined := strings.Join(validPaths, ",")+ opts = append(opts, chromedp.Flag("disable-extensions", false))+ opts = append(opts, chromedp.Flag("load-extension", joined))+ opts = append(opts, chromedp.Flag("disable-extensions-except", joined))+ opts = append(opts, chromedp.Flag("enable-automation", false))+ slog.Info("loading extensions", "paths", joined)+ }} else {- slog.Debug("chrome binary path not found in common locations, letting chromedp search")+ opts = append(opts, chromedp.Flag("disable-extensions", true))}- // Profile+ // User Data Dirif cfg.ProfileDir != "" {opts = append(opts, chromedp.UserDataDir(cfg.ProfileDir))- slog.Debug("chrome user data directory configured", "path", cfg.ProfileDir)}- // Window size+ // Window Sizew, h := randomWindowSize()opts = append(opts, chromedp.WindowSize(w, h))- // Common launch flags- for _, flag := range defaultChromeFlagArgs() {- name := strings.TrimPrefix(flag, "--")- value := ""- if parts := strings.SplitN(name, "=", 2); len(parts) == 2 {- name, value = parts[0], parts[1]- }- opts = append(opts, chromedp.Flag(name, value))- }-- // Extension loading- if len(cfg.ExtensionPaths) > 0 {- joined := strings.Join(cfg.ExtensionPaths, ",")- opts = append(opts, chromedp.Flag("disable-extensions", false))- opts = append(opts, chromedp.Flag("enable-automation", false))- opts = append(opts, chromedp.Flag("load-extension", joined))- opts = append(opts, chromedp.Flag("disable-extensions-except", joined))+ // Timezone+ if cfg.Timezone != "" {+ opts = append(opts, chromedp.Flag("tz", cfg.Timezone))}- // Extra flags+ // Extra Flagsif cfg.ChromeExtraFlags != "" {for _, f := range strings.Fields(cfg.ChromeExtraFlags) {- opts = append(opts, chromedp.Flag(strings.TrimLeft(f, "-"), ""))+ opts = appendExecAllocatorFlag(opts, f)}}- // Timezone- if cfg.Timezone != "" {- opts = append(opts, chromedp.Flag("TZ", cfg.Timezone))- }-- // Override --remote-debugging-port=0 (from DefaultExecAllocatorOptions) with a- // fixed port from the configured range. Chrome 145 stopped printing the- // "DevTools listening on ws://..." message to stderr when port=0 is used, which- // prevents chromedp's ExecAllocator from detecting the actual port. With a known- // fixed port we can fall back to polling /json/version if stderr parsing fails.+ // Debug PortdebugPort := 0if port, err := findFreePort(cfg.InstancePortStart, cfg.InstancePortEnd); err == nil {debugPort = portopts = append(opts, chromedp.Flag("remote-debugging-port", strconv.Itoa(port)))- slog.Debug("chrome debug port assigned", "port", port)- } else {- slog.Debug("could not find free port in configured range, using default port=0", "err", err)}+ opts = append(opts, chromedp.CombinedOutput(newPrefixedLogWriter(os.Stdout, "chrome")))- // Allocator/browser context must be long-lived for the entire bridge instance.- // A short timeout here causes all later tab creation to fail once the deadline expires.ctx, cancel := context.WithCancel(context.Background())-return ctx, cancel, opts, debugPort}-// startChrome starts the Chrome browser with the given options.-// It first tries chromedp's ExecAllocator approach. Chrome 145 and later no-// longer print "DevTools listening on ws://..." to stderr, so if the startup-// times out we fall back to launching Chrome directly via os/exec and connecting-// with a RemoteAllocator (requires debugPort > 0).func startChrome(parentCtx context.Context, cfg *config.RuntimeConfig, opts []chromedp.ExecAllocatorOption, debugPort int) (context.Context, context.CancelFunc, error) {return startChromeWithRecovery(parentCtx, cfg, opts, debugPort, false)}func startChromeWithRecovery(parentCtx context.Context, cfg *config.RuntimeConfig, opts []chromedp.ExecAllocatorOption, debugPort int, retriedProfileLock bool) (context.Context, context.CancelFunc, error) {- slog.Debug("creating chrome allocator")-- // Create allocator context (inner, wraps parentCtx)allocCtx, allocCancel := chromedp.NewExecAllocator(parentCtx, opts...)- slog.Debug("chrome allocator created")-- // Create browser context- slog.Debug("creating chrome context")browserCtx, browserCancel := chromedp.NewContext(allocCtx)- // Initialize stealth scriptstealthSeed := rand.Intn(1000000000)human.SetHumanRandSeed(int64(stealthSeed))seededScript := fmt.Sprintf("var __pinchtab_seed = %d;\nvar __pinchtab_stealth_level = %q;\n", stealthSeed, cfg.StealthLevel) + assets.StealthScript- // Connect to Chrome with a startup timeout so we can detect Chrome 145's silent- // startup behaviour. Chrome 145 no longer prints "DevTools listening on ws://..."- // to stderr, so chromedp's ExecAllocator would block forever waiting for that- // message.- //- // IMPORTANT: we intentionally do NOT derive a timeout context from browserCtx.- // A derived timeout context, when cancelled, propagates through chromedp's internal- // allocator goroutines and kills the Chrome process — defeating the purpose of having- // the fallback. Instead we run chromedp.Run in a goroutine and race it against a- // time.After channel; the browserCtx lifetime remains independent.const chromeStartupTimeout = 20 * time.Second-type runResult struct{ err error }runCh := make(chan runResult, 1)go func() {runCh <- runResult{chromedp.Run(browserCtx, chromedp.ActionFunc(func(ctx context.Context) error {- slog.Debug("chrome connection established, running initial action")return nil}))}}()- slog.Debug("connecting to chrome browser")-var err errorselect {case res := <-runCh:err = res.err- if err != nil {- slog.Debug("chrome initial action failed", "error", err.Error())- } else {- slog.Debug("chrome initial action succeeded")- }case <-time.After(chromeStartupTimeout):- // Chrome started (ExecAllocator launched the process) but never announced- // its DevTools URL via stderr. Wrap as DeadlineExceeded so isStartupTimeout- // recognises it, then fall through to the cleanup + fallback logic below.- slog.Debug("chrome startup timed out", "timeout", chromeStartupTimeout)err = fmt.Errorf("chrome startup timeout after %v: %w", chromeStartupTimeout, context.DeadlineExceeded)}if err != nil {- // Clean up the ExecAllocator and its Chrome process before evaluating error.browserCancel()allocCancel()-errMsg := err.Error()- slog.Debug("evaluating chrome startup error", "error", errMsg)if !retriedProfileLock && isChromeProfileLockError(errMsg) {- slog.Debug("detected chrome profile lock error", "profile", cfg.ProfileDir)- recovered, recoverErr := clearStaleChromeProfileLock(cfg.ProfileDir, errMsg)- if recoverErr != nil {- slog.Warn("failed to recover chrome profile lock", "profile", cfg.ProfileDir, "err", recoverErr)- } else if recovered {- slog.Warn("cleared stale chrome profile lock; retrying chrome startup", "profile", cfg.ProfileDir)+ if recovered, _ := clearStaleChromeProfileLock(cfg.ProfileDir, errMsg); recovered {time.Sleep(250 * time.Millisecond)return startChromeWithRecovery(parentCtx, cfg, opts, debugPort, true)}}- // Chrome binary not found — report clearly and stop.- if strings.Contains(errMsg, "executable file not found") ||- strings.Contains(errMsg, "no such file or directory") {- slog.Error("chrome binary not found", "error", errMsg)-- if cfg.ChromeBinary != "" {- slog.Error("chrome not found at specified path", "path", cfg.ChromeBinary)- } else {- slog.Error("chrome not found in common locations")- }-- slog.Info("install chrome or chromium:")- slog.Info(" debian/ubuntu/raspberry pi: sudo apt install -y chromium-browser")- slog.Info(" fedora/rhel: sudo dnf install -y chromium")- slog.Info(" arch: sudo pacman -S chromium")- slog.Info(" macos: brew install chromium")- slog.Info(" or set 'binary' in config.json to override the chrome binary path")-- return nil, nil, fmt.Errorf("chrome/chromium not found: please install chrome or chromium, or set 'binary' in config.json")- }-- // Startup timeout: Chrome is running but did not announce its DevTools URL via- // stderr. This is the Chrome 145 regression. If we have a fixed debug port we- // can connect directly using RemoteAllocator.if isStartupTimeout(err) && debugPort > 0 {- slog.Warn("chrome startup timeout: DevTools URL not announced via stderr (Chrome 145+ regression), trying direct-launch fallback",- "timeout", chromeStartupTimeout, "port", debugPort)- // Brief pause for ExecAllocator's Chrome process (if any) to fully exit.+ slog.Warn("chrome startup timeout (Chrome 145+ regression), trying direct-launch fallback", "port", debugPort)time.Sleep(500 * time.Millisecond)return startChromeWithRemoteAllocator(parentCtx, cfg, debugPort, stealthSeed, seededScript)}- slog.Error("failed to connect to chrome browser", "error", errMsg)return nil, nil, fmt.Errorf("failed to connect to chrome: %w", err)}- slog.Debug("chrome browser connected successfully")- // Inject stealth script- slog.Debug("injecting stealth script")+ // Inject stealthif err := chromedp.Run(browserCtx, chromedp.ActionFunc(func(ctx context.Context) error {return injectedScript(ctx, seededScript)})); err != nil {browserCancel()allocCancel()- slog.Error("failed to inject stealth script", "error", err.Error())return nil, nil, fmt.Errorf("failed to inject stealth script: %w", err)}- slog.Debug("stealth script injected successfully")return browserCtx, func() {browserCancel()@@ -330,26 +227,15 @@ func startChromeWithRecovery(parentCtx context.Context, cfg *config.RuntimeConfi}, nil}-// isStartupTimeout reports whether err indicates that Chrome started but did not-// announce its DevTools URL within the startup window. This is the signature of-// the Chrome 145 regression where the "DevTools listening on ws://..." message is-// no longer written to stderr.func isStartupTimeout(err error) bool {if errors.Is(err, context.DeadlineExceeded) {return true}msg := err.Error()- return strings.Contains(msg, "deadline exceeded") ||- strings.Contains(msg, "context deadline exceeded")+ return strings.Contains(msg, "deadline exceeded") || strings.Contains(msg, "context deadline exceeded")}-// startChromeWithRemoteAllocator launches Chrome directly via os/exec with a-// fixed debug port, waits for the DevTools endpoint to become available, then-// connects using chromedp's RemoteAllocator. This is the fallback path for-// Chrome 145+, which no longer announces the DevTools URL via stderr.func startChromeWithRemoteAllocator(parentCtx context.Context, cfg *config.RuntimeConfig, debugPort int, stealthSeed int, seededScript string) (context.Context, context.CancelFunc, error) {- slog.Info("using direct-launch fallback for Chrome 145+ compatibility", "port", debugPort)-chromeBinary := cfg.ChromeBinaryif chromeBinary == "" {chromeBinary = findChromeBinary()@@ -359,8 +245,6 @@ func startChromeWithRemoteAllocator(parentCtx context.Context, cfg *config.Runti}args := buildChromeArgs(cfg, debugPort)- slog.Debug("launching chrome directly", "binary", chromeBinary, "port", debugPort, "args", args)-// #nosec G204 -- chromeBinary from user config or findChromeBinary() known system pathscmd := exec.Command(chromeBinary, args...)cmd.Stdout = newPrefixedLogWriter(os.Stdout, "chrome stdout")@@ -368,58 +252,32 @@ func startChromeWithRemoteAllocator(parentCtx context.Context, cfg *config.Runtiif err := cmd.Start(); err != nil {return nil, nil, fmt.Errorf("failed to start chrome directly: %w", err)}- slog.Debug("chrome process started", "pid", cmd.Process.Pid, "port", debugPort)- // Wait for Chrome's DevTools HTTP endpoint to become available.wsURL, err := waitForChromeDevTools(debugPort, 30*time.Second)if err != nil {_ = cmd.Process.Kill()return nil, nil, fmt.Errorf("chrome devtools not ready on port %d: %w", debugPort, err)}- slog.Debug("chrome devtools ready", "wsURL", wsURL, "port", debugPort)- // Connect via RemoteAllocatorremoteAllocCtx, remoteAllocCancel := chromedp.NewRemoteAllocator(parentCtx, wsURL)browserCtx, browserCancel := chromedp.NewContext(remoteAllocCtx)- // Verify the connection- if err := chromedp.Run(browserCtx, chromedp.ActionFunc(func(ctx context.Context) error {- slog.Debug("chrome remote connection established")- return nil- })); err != nil {- browserCancel()- remoteAllocCancel()- _ = cmd.Process.Kill()- return nil, nil, fmt.Errorf("failed to connect to chrome via remote allocator: %w", err)- }-- // Inject stealth script- slog.Debug("injecting stealth script (remote path)")if err := chromedp.Run(browserCtx, chromedp.ActionFunc(func(ctx context.Context) error {return injectedScript(ctx, seededScript)})); err != nil {browserCancel()remoteAllocCancel()_ = cmd.Process.Kill()- slog.Error("failed to inject stealth script (remote path)", "error", err.Error())- return nil, nil, fmt.Errorf("failed to inject stealth script: %w", err)+ return nil, nil, fmt.Errorf("failed to connect/inject via remote: %w", err)}- slog.Debug("stealth script injected successfully (remote path)")-- slog.Info("chrome initialized via direct-launch fallback", "pid", cmd.Process.Pid, "port", debugPort)return browserCtx, func() {browserCancel()remoteAllocCancel()- if err := cmd.Process.Kill(); err != nil && !errors.Is(err, os.ErrProcessDone) {- slog.Warn("failed to kill chrome process on shutdown", "pid", cmd.Process.Pid, "err", err)- }+ _ = cmd.Process.Kill()}, nil}-// findFreePort finds an available TCP port in the inclusive range [start, end].-// It temporarily binds to each port to test availability, releasing it immediately.-// Returns an error if no port in the range is available.func findFreePort(start, end int) (int, error) {for port := start; port <= end; port++ {l, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port))@@ -431,16 +289,13 @@ func findFreePort(start, end int) (int, error) {return 0, fmt.Errorf("no free port available in range %d-%d", start, end)}-// waitForChromeDevTools polls Chrome's /json/version HTTP endpoint until it-// returns a valid browser-level WebSocket URL or the timeout expires.-// Chrome typically becomes ready within 1–3 seconds of startup.func waitForChromeDevTools(port int, timeout time.Duration) (string, error) {endpoint := fmt.Sprintf("http://127.0.0.1:%d/json/version", port)client := &http.Client{Timeout: 2 * time.Second}deadline := time.Now().Add(timeout)for time.Now().Before(deadline) {- resp, err := client.Get(endpoint) //nolint:noctx // intentional: uses client timeout not request context+ resp, err := client.Get(endpoint)if err == nil {var info struct {WebSocketDebuggerURL string `json:"webSocketDebuggerUrl"`@@ -453,13 +308,13 @@ func waitForChromeDevTools(port int, timeout time.Duration) (string, error) {}time.Sleep(250 * time.Millisecond)}-return "", fmt.Errorf("chrome devtools not ready on port %d after %v", port, timeout)}func defaultChromeFlagArgs() []string {return []string{"--disable-background-networking",+ "--enable-features=NetworkService,NetworkServiceInProcess","--disable-background-timer-throttling","--disable-backgrounding-occluded-windows","--disable-breakpad",@@ -467,6 +322,7 @@ func defaultChromeFlagArgs() []string {"--disable-client-side-phishing-detection","--disable-default-apps","--disable-dev-shm-usage",+ "--disable-features=site-per-process,Translate,BlinkGenPropertyTrees","--hide-crash-restore-bubble","--disable-hang-monitor","--disable-ipc-flooding-protection",@@ -477,30 +333,22 @@ func defaultChromeFlagArgs() []string {"--disable-sync","--force-color-profile=srgb","--metrics-recording-only",- "--no-first-run",- "--no-default-browser-check","--noerrdialogs","--safebrowsing-disable-auto-update","--password-store=basic","--use-mock-keychain",- // Stealth"--disable-automation","--disable-blink-features=AutomationControlled",+ "--no-sandbox",}}-// buildChromeArgs constructs the Chrome command-line arguments for direct launch.-// This mirrors the flags applied by setupAllocator/DefaultExecAllocatorOptions-// and is used exclusively by the direct-launch fallback path.func buildChromeArgs(cfg *config.RuntimeConfig, port int) []string {args := append([]string{fmt.Sprintf("--remote-debugging-port=%d", port)}, defaultChromeFlagArgs()...)if len(cfg.ExtensionPaths) > 0 {joined := strings.Join(cfg.ExtensionPaths, ",")- args = append(args,- "--load-extension="+joined,- "--disable-extensions-except="+joined,- )+ args = append(args, "--load-extension="+joined, "--disable-extensions-except="+joined)} else {args = append(args, "--disable-extensions")}@@ -509,6 +357,7 @@ func buildChromeArgs(cfg *config.RuntimeConfig, port int) []string {args = append(args,"--headless=new","--disable-gpu",+ "--enable-unsafe-swiftshader",)}@@ -530,14 +379,10 @@ func buildChromeArgs(cfg *config.RuntimeConfig, port int) []string {return args}-// injectedScript injects stealth code into the browserfunc injectedScript(ctx context.Context, script string) error {- // This is a placeholder - actual implementation would use chromedp- // to evaluate the script in the browser context- return nil+ return nil // Placeholder}-// randomWindowSize returns a random common window sizefunc randomWindowSize() (int, int) {sizes := [][2]int{{1920, 1080}, {1366, 768}, {1536, 864}, {1440, 900},@@ -554,11 +399,7 @@ type prefixedLogWriter struct {}func newPrefixedLogWriter(dst io.Writer, prefix string) *prefixedLogWriter {- return &prefixedLogWriter{- dst: dst,- prefix: prefix,- buf: make([]byte, 0, 1024),- }+ return &prefixedLogWriter{dst: dst, prefix: prefix, buf: make([]byte, 0, 1024)}}func (w *prefixedLogWriter) Write(p []byte) (int, error) {@@ -570,18 +411,11 @@ func (w *prefixedLogWriter) Write(p []byte) (int, error) {}line := w.buf[:idx]w.buf = w.buf[idx+1:]- if err := w.writeLine(line); err != nil {- return 0, err+ if len(line) > 0 {+ if _, err := fmt.Fprintf(w.dst, "%s: %s\n", w.prefix, string(line)); err != nil {+ return 0, err+ }}}return len(p), nil}--func (w *prefixedLogWriter) writeLine(line []byte) error {- text := string(line)- if text == "" {- return nil- }- _, err := fmt.Fprintf(w.dst, "%s: %s\n", w.prefix, text)- return err-}diff --git a/internal/cli/actions/actions_instance.go b/internal/cli/actions/actions_instance.goindex c7d04bec..4a0f7d6e 100644--- a/internal/cli/actions/actions_instance.go+++ b/internal/cli/actions/actions_instance.go@@ -19,6 +19,9 @@ func InstanceStart(client *http.Client, base, token string, cmd *cobra.Command)if v, _ := cmd.Flags().GetString("port"); v != "" {body["port"] = v}+ if exts, _ := cmd.Flags().GetStringArray("extension"); len(exts) > 0 {+ body["extensionPaths"] = exts+ }apiclient.DoPost(client, base, token, "/instances/start", body)}diff --git a/internal/orchestrator/orchestrator.go b/internal/orchestrator/orchestrator.goindex b421b9fb..d6c74809 100644--- a/internal/orchestrator/orchestrator.go+++ b/internal/orchestrator/orchestrator.go@@ -361,8 +361,23 @@ func (o *Orchestrator) writeChildConfig(port, profilePath, instanceStateDir stri}noRestore := truefc.InstanceDefaults.NoRestore = &noRestore+if len(extensionPaths) > 0 {- fc.Browser.ExtensionPaths = append([]string(nil), extensionPaths...)+ seen := make(map[string]bool)+ unique := make([]string, 0, len(fc.Browser.ExtensionPaths)+len(extensionPaths))+ for _, p := range fc.Browser.ExtensionPaths {+ if !seen[p] {+ seen[p] = true+ unique = append(unique, p)+ }+ }+ for _, p := range extensionPaths {+ if !seen[p] {+ seen[p] = true+ unique = append(unique, p)+ }+ }+ fc.Browser.ExtensionPaths = unique}configPath := filepath.Join(instanceStateDir, "config.json")