grafana/k6 · error
pressing the mouse button on x:%f y:%f: %w
Error message
pressing the mouse button on x:%f y:%f: %w
What it means
Thrown by Mouse.Down() when the internal m.down() fails at the CDP level. Down() dispatches Input.dispatchMouseEvent(mousePressed) at the mouse's current coordinates (m.x, m.y), so it fails when the DevTools session is gone (page closed, target crashed, browser exit) or the protocol call is rejected mid-press.
Source
Thrown at internal/js/modules/k6/browser/common/mouse.go:80
return err
}
}
return nil
}
// DblClick will trigger Click twice in quick succession.
func (m *Mouse) DblClick(x float64, y float64, opts *MouseDblClickOptions) error {
if err := m.click(x, y, opts.ToMouseClickOptions()); err != nil {
return fmt.Errorf("double clicking on x:%f y:%f: %w", x, y, err)
}
return nil
}
// Down will trigger a MouseDown event in the browser.
func (m *Mouse) Down(opts *MouseDownUpOptions) error {
if err := m.down(opts); err != nil {
return fmt.Errorf("pressing the mouse button on x:%f y:%f: %w", m.x, m.y, err)
}
return nil
}
func (m *Mouse) down(opts *MouseDownUpOptions) error {
m.button = input.MouseButton(opts.Button)
action := input.DispatchMouseEvent(input.MousePressed, m.x, m.y).
WithButton(input.MouseButton(opts.Button)).
WithModifiers(input.Modifier(m.keyboard.modifiers)).
WithClickCount(opts.ClickCount)
if err := action.Do(cdp.WithExecutor(m.ctx, m.session)); err != nil {
return fmt.Errorf("mouse down: %w", err)
}
return nil
}
// Up will trigger a MouseUp event in the browser.
func (m *Mouse) Up(opts *MouseDownUpOptions) error {View on GitHub (pinned to 93accf6570)
Solutions
- Check page.isClosed() and browser connectivity before starting a press-hold gesture
- Perform down/move/up in one tight sequence with no awaits on navigation in between
- Re-establish the page and restart the gesture if the session dropped
- Avoid triggering actions in mousedown handlers that navigate away mid-gesture
Example fix
// before
await page.mouse.down();
await page.goto('/'); // gesture context lost
await page.mouse.up();
// after
await page.mouse.down();
await page.mouse.move(200, 300, { steps: 5 });
await page.mouse.up(); // complete gesture before any navigation Defensive patterns
Strategy: try-catch
Validate before calling
if (page.isClosed()) throw new Error('page closed before press');
await page.mouse.move(x, y);
await page.mouse.down(); Try / catch
try {
await page.mouse.down();
} catch (e) {
if (/target closed|session|context destroyed/i.test(e.message)) {
throw new Error('mouse session lost; restart gesture on a new page');
}
throw e;
} Prevention
- Complete down/move/up without intervening navigation
- Check the page is open before each gesture phase
- Create a fresh Mouse per page; never reuse across pages
When it happens
Trigger: mouse.down() called after page.close(), browser.disconnect(), or a target crash; pressing while a navigation destroys the session; dispatch rejected due to an invalid state in the input domain.
Common situations: Simulating drag-and-drop (down/move/up) where the drag triggers navigation or the page closes mid-gesture; long-running tests where the browser died between operations; forgetting to move the mouse to a valid position first.
Related errors
- releasing the mouse button on x:%f y:%f: %w
- moving the mouse pointer to x:%f y:%f: %w
- clicking on x:%f y:%f: %w
- double clicking on x:%f y:%f: %w
- mouse down: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/a48ae03770a70952.
Report an issue: GitHub.