Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

8F-9: CDP-level timezone override via Emulation.setTimezoneOverride

bot410497e54d74
diff --git a/config.go b/config.go
index f59a9142..59beca78 100644
--- a/config.go
+++ b/config.go
@@ -53,6 +53,7 @@ var (
noRestore = os.Getenv("BRIDGE_NO_RESTORE") == "true"
profileDir = envOr("BRIDGE_PROFILE", filepath.Join(homeDir(), ".pinchtab", "chrome-profile"))
chromeVersion = envOr("BRIDGE_CHROME_VERSION", "133.0.6943.98")
+ timezone = os.Getenv("BRIDGE_TIMEZONE") // e.g. "America/New_York"
actionTimeout = 15 * time.Second
navigateTimeout = 30 * time.Second
shutdownTimeout = 10 * time.Second
diff --git a/integration_test.go b/integration_test.go
index 4a400b55..0fff36d4 100644
--- a/integration_test.go
+++ b/integration_test.go
@@ -14,6 +14,7 @@ import (
"testing"
"time"
+ "github.com/chromedp/cdproto/emulation"
"github.com/chromedp/cdproto/page"
"github.com/chromedp/chromedp"
)
@@ -301,6 +302,40 @@ func TestFingerprintRotation(t *testing.T) {
}
}
+// TestCDPTimezoneOverride verifies that Emulation.setTimezoneOverride works at CDP level.
+func TestCDPTimezoneOverride(t *testing.T) {
+ b, cleanup := testBridge(t)
+ defer cleanup()
+
+ // Apply CDP timezone override
+ ctx, _, _ := b.TabContext("")
+ tCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
+ defer cancel()
+
+ if err := chromedp.Run(tCtx,
+ chromedp.ActionFunc(func(ctx context.Context) error {
+ return emulation.SetTimezoneOverride("Pacific/Auckland").Do(ctx)
+ }),
+ ); err != nil {
+ t.Fatalf("setTimezoneOverride: %v", err)
+ }
+
+ navigateAndWait(t, b, "data:text/html,<h1>tz</h1>")
+
+ ctx2, _, _ := b.TabContext("")
+ tCtx2, cancel2 := context.WithTimeout(ctx2, 5*time.Second)
+ defer cancel2()
+
+ var tz string
+ if err := chromedp.Run(tCtx2, chromedp.Evaluate(`Intl.DateTimeFormat().resolvedOptions().timeZone`, &tz)); err != nil {
+ t.Fatalf("evaluate: %v", err)
+ }
+
+ if tz != "Pacific/Auckland" {
+ t.Errorf("timezone = %q, want Pacific/Auckland", tz)
+ }
+}
+
// TestStealthStatusEndpoint verifies the /stealth/status handler returns valid data with a live browser.
func TestStealthStatusEndpoint(t *testing.T) {
b, cleanup := testBridge(t)
diff --git a/main.go b/main.go
index 18d32570..eb5091d1 100644
--- a/main.go
+++ b/main.go
@@ -10,6 +10,7 @@ import (
"os/signal"
"syscall"
+ "github.com/chromedp/cdproto/emulation"
"github.com/chromedp/cdproto/page"
"github.com/chromedp/chromedp"
)
@@ -118,6 +119,19 @@ func main() {
os.Exit(1)
}
+ // CDP-level timezone override (more reliable than JS-only approach)
+ if timezone != "" {
+ if err := chromedp.Run(browserCtx,
+ chromedp.ActionFunc(func(ctx context.Context) error {
+ return emulation.SetTimezoneOverride(timezone).Do(ctx)
+ }),
+ ); err != nil {
+ slog.Warn("timezone override failed", "tz", timezone, "err", err)
+ } else {
+ slog.Info("timezone override", "tz", timezone)
+ }
+ }
+
bridge.browserCtx = browserCtx
bridge.tabs = make(map[string]*TabEntry)
bridge.snapshots = make(map[string]*refCache)