Skip to content

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

Fix silent error swallowing in animations.go

Roopeshe7427e468de3
diff --git a/internal/bridge/animations.go b/internal/bridge/animations.go
index e2876269..18e367de 100644
--- a/internal/bridge/animations.go
+++ b/internal/bridge/animations.go
@@ -20,8 +20,8 @@ const DisableAnimationsCSS = `
// InjectNoAnimations adds a persistent script (via CDP) that disables CSS
// animations on every document load. Used when BRIDGE_NO_ANIMATIONS=true.
-func (b *Bridge) InjectNoAnimations(ctx context.Context) {
- _ = chromedp.Run(ctx,
+func (b *Bridge) InjectNoAnimations(ctx context.Context) error {
+ return chromedp.Run(ctx,
chromedp.ActionFunc(func(ctx context.Context) error {
_, err := page.AddScriptToEvaluateOnNewDocument(DisableAnimationsCSS).Do(ctx)
return err
@@ -37,8 +37,8 @@ func (b *Bridge) InjectNoAnimations(ctx context.Context) {
// DisableAnimationsOnce runs the animation-disabling CSS on the current page
// (one-shot, for per-request ?noAnimations=true).
-func DisableAnimationsOnce(ctx context.Context) {
- _ = chromedp.Run(ctx,
+func DisableAnimationsOnce(ctx context.Context) error {
+ return chromedp.Run(ctx,
chromedp.Evaluate(DisableAnimationsCSS, nil),
chromedp.ActionFunc(func(ctx context.Context) error {
return emulation.SetEmulatedMedia().
diff --git a/internal/bridge/animations_test.go b/internal/bridge/animations_test.go
index d34ebb23..367280d7 100644
--- a/internal/bridge/animations_test.go
+++ b/internal/bridge/animations_test.go
@@ -1,6 +1,7 @@
package bridge
import (
+ "context"
"strings"
"testing"
@@ -26,3 +27,22 @@ func TestInjectNoAnimations(t *testing.T) {
t.Error("Expected NoAnimations to be true")
}
}
+
+func TestDisableAnimationsOnceReturnsErrorWhenContextCanceled(t *testing.T) {
+ ctx, cancel := context.WithCancel(context.Background())
+ cancel()
+
+ if err := DisableAnimationsOnce(ctx); err == nil {
+ t.Fatal("expected error for canceled context")
+ }
+}
+
+func TestInjectNoAnimationsReturnsErrorWhenContextCanceled(t *testing.T) {
+ ctx, cancel := context.WithCancel(context.Background())
+ cancel()
+
+ b := &Bridge{}
+ if err := b.InjectNoAnimations(ctx); err == nil {
+ t.Fatal("expected error for canceled context")
+ }
+}
diff --git a/internal/bridge/bridge.go b/internal/bridge/bridge.go
index be7137ee..155785e3 100644
--- a/internal/bridge/bridge.go
+++ b/internal/bridge/bridge.go
@@ -84,7 +84,9 @@ func (b *Bridge) tabSetup(ctx context.Context) {
}
b.injectStealth(ctx)
if b.Config.NoAnimations {
- b.InjectNoAnimations(ctx)
+ if err := b.InjectNoAnimations(ctx); err != nil {
+ slog.Warn("no-animations injection failed", "err", err)
+ }
}
}
diff --git a/internal/handlers/screenshot.go b/internal/handlers/screenshot.go
index f88f7335..5f7ea4ff 100644
--- a/internal/handlers/screenshot.go
+++ b/internal/handlers/screenshot.go
@@ -42,7 +42,10 @@ func (h *Handlers) HandleScreenshot(w http.ResponseWriter, r *http.Request) {
go web.CancelOnClientDone(r.Context(), tCancel)
if reqNoAnim && !h.Config.NoAnimations {
- bridge.DisableAnimationsOnce(tCtx)
+ if err := bridge.DisableAnimationsOnce(tCtx); err != nil {
+ web.Error(w, 500, fmt.Errorf("disable animations: %w", err))
+ return
+ }
}
var buf []byte
diff --git a/internal/handlers/snapshot.go b/internal/handlers/snapshot.go
index 1ab5f9de..14bfd7d1 100644
--- a/internal/handlers/snapshot.go
+++ b/internal/handlers/snapshot.go
@@ -97,7 +97,10 @@ func (h *Handlers) HandleSnapshot(w http.ResponseWriter, r *http.Request) {
go web.CancelOnClientDone(r.Context(), tCancel)
if reqNoAnim && !h.Config.NoAnimations {
- bridge.DisableAnimationsOnce(tCtx)
+ if err := bridge.DisableAnimationsOnce(tCtx); err != nil {
+ web.Error(w, 500, fmt.Errorf("disable animations: %w", err))
+ return
+ }
}
var rawResult json.RawMessage