Add context support to InteractiveBrowser methods #86

Closed
opened 2026-03-17 01:54:46 +00:00 by Claude · 0 comments
Collaborator

Problem

None of the InteractiveBrowser methods (Navigate, Screenshot, Cookies, MouseClick, etc.) accept a context.Context or have timeouts. If the Playwright process crashes or the remote server becomes unresponsive, these operations block forever.

This is a significant issue for the captcha proxy system in Mort, where a hung Playwright operation causes the entire captcha session to appear frozen. The user sees a stalled browser with no recourse but restarting the bot.

Current Workaround

A watchdog timer in the captcha proxy's screenshot loop detects when no successful screenshot has been produced for 30 seconds and force-closes the session. This is a blunt workaround — ideally each operation would respect a context/timeout natively.

Proposed Change

Add context.Context as the first parameter to InteractiveBrowser methods, or add timeout variants:

type InteractiveBrowser interface {
    Navigate(ctx context.Context, url string) (string, error)
    Screenshot(ctx context.Context, quality int) ([]byte, error)
    Cookies(ctx context.Context) ([]Cookie, error)
    MouseClick(ctx context.Context, x, y float64, button string) error
    // ... etc
}

This would be a breaking API change. An alternative is adding a SetTimeout(d time.Duration) method or a WithContext(ctx context.Context) InteractiveBrowser wrapper.

Filed from mort issue steve/mort#1159 (captcha proxy reliability overhaul, Bug 4).

## Problem None of the `InteractiveBrowser` methods (`Navigate`, `Screenshot`, `Cookies`, `MouseClick`, etc.) accept a `context.Context` or have timeouts. If the Playwright process crashes or the remote server becomes unresponsive, these operations block forever. This is a significant issue for the captcha proxy system in Mort, where a hung Playwright operation causes the entire captcha session to appear frozen. The user sees a stalled browser with no recourse but restarting the bot. ## Current Workaround A watchdog timer in the captcha proxy's screenshot loop detects when no successful screenshot has been produced for 30 seconds and force-closes the session. This is a blunt workaround — ideally each operation would respect a context/timeout natively. ## Proposed Change Add `context.Context` as the first parameter to `InteractiveBrowser` methods, or add timeout variants: ```go type InteractiveBrowser interface { Navigate(ctx context.Context, url string) (string, error) Screenshot(ctx context.Context, quality int) ([]byte, error) Cookies(ctx context.Context) ([]Cookie, error) MouseClick(ctx context.Context, x, y float64, button string) error // ... etc } ``` This would be a breaking API change. An alternative is adding a `SetTimeout(d time.Duration)` method or a `WithContext(ctx context.Context) InteractiveBrowser` wrapper. ## Related Filed from mort issue https://gitea.stevedudenhoeffer.com/steve/mort/issues/1159 (captcha proxy reliability overhaul, Bug 4).
Sign in to join this conversation.