{"record":{"id":"b5754b303c3ecbba","repo":"grafana/k6","slug":"clicking-on-x-f-y-f-w","errorCode":null,"errorMessage":"clicking on x:%f y:%f: %w","messagePattern":"clicking on x:(.+?) y:(.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/mouse.go","lineNumber":39,"sourceCode":"\tbutton          input.MouseButton\n}\n\n// NewMouse creates a new mouse.\nfunc NewMouse(ctx context.Context, s session, f *Frame, ts *TimeoutSettings, k *Keyboard) *Mouse {\n\treturn &Mouse{\n\t\tctx:             ctx,\n\t\tsession:         s,\n\t\tframe:           f,\n\t\ttimeoutSettings: ts,\n\t\tkeyboard:        k,\n\t\tbutton:          input.None,\n\t}\n}\n\n// Click will trigger a series of MouseMove, MouseDown and MouseUp events in the browser.\nfunc (m *Mouse) Click(x float64, y float64, opts *MouseClickOptions) error {\n\tif err := m.click(x, y, opts); err != nil {\n\t\treturn fmt.Errorf(\"clicking on x:%f y:%f: %w\", x, y, err)\n\t}\n\treturn nil\n}\n\nfunc (m *Mouse) click(x float64, y float64, opts *MouseClickOptions) error {\n\tmouseDownUpOpts := opts.ToMouseDownUpOptions()\n\tif err := m.move(x, y, NewMouseMoveOptions()); err != nil {\n\t\treturn err\n\t}\n\tfor i := 0; i < int(mouseDownUpOpts.ClickCount); i++ {\n\t\tif err := m.down(mouseDownUpOpts); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif opts.Delay != 0 {\n\t\t\tt := time.NewTimer(time.Duration(opts.Delay) * time.Millisecond)\n\t\t\tselect {\n\t\t\tcase <-m.ctx.Done():\n\t\t\t\tt.Stop()","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/mouse.go#L21-L57","documentation":"Thrown by Mouse.Click(x, y) when the internal click sequence (move + N x down/up) fails at the CDP level. The mouse API targets raw viewport coordinates, not selectors, so failures are usually environmental: the page/context was closed or navigated mid-sequence, the browser target crashed, or the CDP Input.dispatchMouseEvent call was rejected.","triggerScenarios":"mouse.click(x, y) after page.close() or during navigation that destroys the session; coordinates far outside the viewport; browser process crash or DevTools session drop while dispatching.","commonSituations":"Clicking coordinates captured earlier from boundingBox() after the page re-rendered or navigated; using mouse after a timeout that closed the page; clicking beyond viewport bounds without scrolling.","solutions":["Ensure the page and browser context are still open before dispatching (check page.isClosed())","Recompute coordinates from a fresh element.boundingBox() immediately before clicking","Scroll the element into view so coordinates land inside the viewport","Wrap mouse calls in try/catch and re-locate after navigation"],"exampleFix":"// before\nconst box = await page.locator('#btn').boundingBox();\nawait page.goto(nextUrl);\nawait page.mouse.click(box.x + 5, box.y + 5); // stale coords, session churn\n\n// after\nawait page.goto(nextUrl);\nconst box = await page.locator('#btn').boundingBox();\nif (box) await page.mouse.click(box.x + 5, box.y + 5);","handlingStrategy":"try-catch","validationCode":"if (page.isClosed()) throw new Error('page closed');\nconst box = await page.locator('#btn').boundingBox();\nif (!box) throw new Error('element has no bounding box');\nawait page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);","typeGuard":"function isValidPoint(box, x, y) {\n  return !!box && x >= 0 && y >= 0 && x <= box.width && y <= box.height;\n}","tryCatchPattern":"try {\n  await page.mouse.click(x, y);\n} catch (e) {\n  if (/closed|destroyed|target closed/i.test(e.message)) {\n    throw new Error('page/session gone before click');\n  }\n  throw e;\n}","preventionTips":["Always derive coordinates from a fresh boundingBox() in the same tick","Prefer selector-based locator.click() unless exact coordinates matter","Check page.isClosed() before raw mouse input"],"tags":["browser","mouse","cdp","coordinates"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}