High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
feat: add detailed logging for Chrome initialization debugging
Mariod6ea6ad336d1
diff --git a/internal/bridge/init.go b/internal/bridge/init.goindex 5ecd0050..754273d0 100644--- a/internal/bridge/init.go+++ b/internal/bridge/init.go@@ -17,17 +17,21 @@ import (// 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 := setupAllocator(cfg)+ slog.Debug("chrome allocator configured", "headless", cfg.Headless)// Start Chrome browserbrowserCtx, browserCancel, err := startChrome(allocCtx, cfg, opts)if err != nil {allocCancel()+ slog.Error("chrome initialization failed", "headless", cfg.Headless, "error", err.Error())return nil, nil, nil, nil, fmt.Errorf("failed to start chrome: %w", err)}- slog.Info("chrome initialized", "headless", cfg.Headless, "profile", cfg.ProfileDir)+ slog.Info("chrome initialized successfully", "headless", cfg.Headless, "profile", cfg.ProfileDir)return allocCtx, allocCancel, browserCtx, browserCancel, nil}@@ -35,21 +39,30 @@ func InitChrome(cfg *config.RuntimeConfig) (context.Context, context.CancelFunc,func setupAllocator(cfg *config.RuntimeConfig) (context.Context, context.CancelFunc, []chromedp.ExecAllocatorOption) {opts := chromedp.DefaultExecAllocatorOptions[:]+ // Log configuration+ slog.Debug("configuring chrome allocator", "headless", cfg.Headless, "binary", cfg.ChromeBinary, "profile_dir", cfg.ProfileDir)+// Headless modeif cfg.Headless {opts = append(opts, chromedp.Headless)+ slog.Debug("chrome mode set to headless")} else {opts = append(opts, chromedp.Flag("headless", false))+ slog.Debug("chrome mode set to headed (visible window)")}// Chrome binaryif cfg.ChromeBinary != "" {opts = append(opts, chromedp.ExecPath(cfg.ChromeBinary))+ slog.Debug("chrome binary path configured", "path", cfg.ChromeBinary)+ } else {+ slog.Debug("chrome binary path not specified, using system PATH")}// Profileif cfg.ProfileDir != "" {opts = append(opts, chromedp.UserDataDir(cfg.ProfileDir))+ slog.Debug("chrome user data directory configured", "path", cfg.ProfileDir)}// Window size@@ -82,10 +95,14 @@ func setupAllocator(cfg *config.RuntimeConfig) (context.Context, context.CancelF// startChrome starts the Chrome browser with the given optionsfunc startChrome(allocCtx context.Context, cfg *config.RuntimeConfig, opts []chromedp.ExecAllocatorOption) (context.Context, context.CancelFunc, error) {+ slog.Debug("creating chrome allocator")+// Create allocator contextallocCtx, allocCancel := chromedp.NewExecAllocator(allocCtx, opts...)+ slog.Debug("chrome allocator created")// Create browser context+ slog.Debug("creating chrome context")browserCtx, cancel := chromedp.NewContext(allocCtx)// Initialize stealth script@@ -94,20 +111,26 @@ func startChrome(allocCtx context.Context, cfg *config.RuntimeConfig, opts []chrseededScript := fmt.Sprintf("var __pinchtab_seed = %d;\nvar __pinchtab_stealth_level = %q;\n", stealthSeed, cfg.StealthLevel) + assets.StealthScript// Start browser (connect to Chrome)+ slog.Debug("connecting to chrome browser")if err := chromedp.Run(browserCtx); err != nil {cancel()allocCancel()+ slog.Error("failed to connect to chrome browser", "error", err.Error())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")if err := chromedp.Run(browserCtx, chromedp.ActionFunc(func(ctx context.Context) error {return injectedScript(ctx, seededScript)})); err != nil {cancel()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() {cancel()