grafana/k6 · error
moving the mouse pointer to x:%f y:%f: %w
Error message
moving the mouse pointer to x:%f y:%f: %w
What it means
Thrown by Mouse.Move(x, y) when the internal m.move() fails. Move() dispatches one or more Input.dispatchMouseEvent(mouseMoved) events interpolated over opts.Steps from the current position to (x, y). Any single step failing (session gone, target crashed) aborts with this wrapped error; a steps value of 0 makes no dispatches and cannot fail this way.
Source
Thrown at internal/js/modules/k6/browser/common/mouse.go:121
}
func (m *Mouse) up(opts *MouseDownUpOptions) error {
m.button = input.None
action := input.DispatchMouseEvent(input.MouseReleased, 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 up: %w", err)
}
return nil
}
// Move will trigger a MouseMoved event in the browser.
func (m *Mouse) Move(x float64, y float64, opts *MouseMoveOptions) error {
if err := m.move(x, y, opts); err != nil {
return fmt.Errorf("moving the mouse pointer to x:%f y:%f: %w", x, y, err)
}
return nil
}
func (m *Mouse) move(x float64, y float64, opts *MouseMoveOptions) error {
fromX := m.x
fromY := m.y
m.x = x
m.y = y
for i := int64(1); i <= opts.Steps; i++ {
x := fromX + (m.x-fromX)*float64(i/opts.Steps)
y := fromY + (m.y-fromY)*float64(i/opts.Steps)
action := input.DispatchMouseEvent(input.MouseMoved, x, y).
WithButton(m.button).
WithModifiers(input.Modifier(m.keyboard.modifiers))
if err := action.Do(cdp.WithExecutor(m.ctx, m.session)); err != nil {
return fmt.Errorf("mouse move: %w", err)
}View on GitHub (pinned to 93accf6570)
Solutions
- Keep gestures short: use a modest steps count and avoid awaits/navigation during the move
- Verify page.isClosed() before starting the move
- Recreate the page and restart the gesture if this fires
- Stabilize the environment (memory, remote endpoint) if crashes are frequent
Example fix
// before
await page.mouse.move(600, 400, { steps: 50 }); // long exposure window
// after
if (page.isClosed()) throw new Error('page closed');
await page.mouse.move(600, 400, { steps: 10 }); Defensive patterns
Strategy: try-catch
Validate before calling
if (page.isClosed()) throw new Error('page closed');
await page.mouse.move(x, y, { steps: 10 }); Try / catch
try {
await page.mouse.move(x, y, { steps });
} catch (e) {
if (/target closed|session/i.test(e.message)) {
throw new Error('session lost mid-move; restart gesture');
}
throw e;
} Prevention
- Use a small steps count (5-10) to limit exposure
- No navigation or long awaits during multi-step moves
- Verify page state before each gesture
When it happens
Trigger: mouse.move(x, y, {steps}) where the session dies mid-loop: page.close() during the move, browser crash, target destroyed by navigation between steps; very many steps extending exposure to session loss.
Common situations: Drag-and-drop gestures with many steps across a slow page; move interrupted by SPA navigation triggered by hover; remote browser connection drop mid-gesture.
Related errors
- pressing the mouse button on x:%f y:%f: %w
- releasing the mouse button on 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/870dcf02b8df51ef.
Report an issue: GitHub.