{"record":{"id":"1ee3d9bc863b1cfe","repo":"grafana/k6","slug":"getting-node-in-frame-w","errorCode":null,"errorMessage":"getting node in frame: %w","messagePattern":"getting node in frame: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1156,"sourceCode":"\tdocumentHandle, ok := res.(*ElementHandle)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected result type while getting document element: %T\", res)\n\t}\n\tdefer func() {\n\t\tif err := documentHandle.Dispose(); err != nil {\n\t\t\terr = fmt.Errorf(\"disposing document element: %w\", err)\n\t\t\trerr = errors.Join(err, rerr)\n\t\t}\n\t}()\n\n\tif documentHandle.remoteObject.ObjectID == \"\" {\n\t\treturn nil, err\n\t}\n\n\tvar node *cdp.Node\n\taction := dom.DescribeNode().WithObjectID(documentHandle.remoteObject.ObjectID)\n\tif node, err = action.Do(cdp.WithExecutor(h.ctx, h.session)); err != nil {\n\t\treturn nil, fmt.Errorf(\"getting node in frame: %w\", err)\n\t}\n\tif node == nil || node.FrameID == \"\" {\n\t\treturn nil, fmt.Errorf(\"no frame found for node: %w\", err)\n\t}\n\n\tframe, ok := h.frame.manager.getFrameByID(node.FrameID)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"no frame found for id %s\", node.FrameID)\n\t}\n\n\treturn frame, nil\n}\n\n// Press scrolls element into view and presses the given keys.\nfunc (h *ElementHandle) Press(key string, opts *ElementHandlePressOptions) error {\n\tpress := func(apiCtx context.Context, handle *ElementHandle) (any, error) {\n\t\treturn nil, handle.press(apiCtx, key, KeyboardOptions{})\n\t}","sourceCodeStart":1138,"sourceCodeEnd":1174,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L1138-L1174","documentation":"Thrown by ElementHandle.OwnerFrame() (internal/js/modules/k6/browser/common/element_handle.go:1156) when the CDP call DOM.describeNode, executed with the document element's remote object ID, returns a protocol-level error. The wrapped error comes straight from the Chrome DevTools Protocol session, so the root cause is almost always a lifecycle race (navigation, target close) rather than bad input.","triggerScenarios":"Calling any API that resolves an element's owner frame (selectors containing frame navigation like 'iframe >> button', setInputFiles internals) while the page navigates, the tab/target is closed, or the browser is shutting down at k6 iteration end; the CDP session or execution context is destroyed mid-call.","commonSituations":"Holding a stale ElementHandle across a click that triggers navigation; k6 closes the browser while an async browser op is still in flight; heavy load causes the target to crash. Typically intermittent, load-correlated failures.","solutions":["Re-acquire the element handle after any action that can navigate (click, goto) before calling frame-dependent APIs","Await page.waitForLoadState()/waitForNavigation after navigating actions, then retry the operation","Ensure your script is not closing the page/browser while operations on handles are still running (avoid fire-and-forget promises)","Increase the action/timeout budget if failure correlates with high load or slowMo"],"exampleFix":"// before\nconst el = page.locator('iframe >> button'); // resolves owner frame internally\nawait page.click('a.next'); // navigation starts\n// after\nawait page.click('a.next');\nawait page.waitForLoadState('load');\nconst el = page.locator('iframe >> button'); // re-query after navigation settles","handlingStrategy":"retry","validationCode":"// Verify the element is still live before a frame-dependent op\nconst visible = await el.isVisible();\nif (!visible) throw new Error('element gone; re-query before owner-frame op');","typeGuard":null,"tryCatchPattern":"try {\n  const f = el.ownerFrame(); // or locator with '>>' frame nav\n} catch (e) {\n  if (/getting node in frame/.test(e.message)) { await page.waitForLoadState(); /* retry once */ }\n  else throw e;\n}","preventionTips":["Re-query elements after any click/goto that can navigate","Await load states before frame-dependent selectors","Never let the browser close while browser promises are pending"],"tags":["browser","cdp","navigation","race-condition","element-handle"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}