{"record":{"id":"38577938b60d8a2c","repo":"grafana/k6","slug":"resolving-dom-node-w","errorCode":null,"errorMessage":"resolving DOM node: %w","messagePattern":"resolving DOM node: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/execution_context.go","lineNumber":105,"sourceCode":"\n// Adopts specified backend node into this execution context from another execution context.\nfunc (e *ExecutionContext) adoptBackendNodeID(backendNodeID cdp.BackendNodeID) (*ElementHandle, error) {\n\te.logger.Debugf(\n\t\t\"ExecutionContext:adoptBackendNodeID\",\n\t\t\"sid:%s stid:%s fid:%s ectxid:%d furl:%q bnid:%d\",\n\t\te.sid, e.stid, e.fid, e.id, e.furl, backendNodeID)\n\n\tvar (\n\t\tremoteObj *runtime.RemoteObject\n\t\terr       error\n\t)\n\n\taction := dom.ResolveNode().\n\t\tWithBackendNodeID(backendNodeID).\n\t\tWithExecutionContextID(e.id)\n\n\tif remoteObj, err = action.Do(cdp.WithExecutor(e.ctx, e.session)); err != nil {\n\t\treturn nil, fmt.Errorf(\"resolving DOM node: %w\", err)\n\t}\n\n\t// This can occur due to race conditions between trying to click on an element\n\t// and chrome moving on (e.g. navigating).\n\tif remoteObj == nil {\n\t\treturn nil, fmt.Errorf(`the page may have navigated away or the element is\n\t\t\tnow missing. It might happen when k6 and/or Chrome are overloaded. You\n\t\t\tmight need to increase the compute resources`)\n\t}\n\n\treturn NewJSHandle(e.ctx, e.session, e, e.frame, remoteObj, e.logger).AsElement(), nil\n}\n\n// Adopts the specified element handle into this execution context from another execution context.\nfunc (e *ExecutionContext) adoptElementHandle(eh *ElementHandle) (*ElementHandle, error) {\n\tvar (\n\t\tefid cdp.FrameID\n\t\tesid target.SessionID","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/execution_context.go#L87-L123","documentation":"ExecutionContext.adoptBackendNodeID wraps a failed CDP DOM.resolveNode call. k6 resolves a backend node ID into a remote object inside a specific execution context (used when adopting element handles across contexts/frames, e.g. inside waitForSelector). The CDP command fails when the backend node ID is stale (page navigated, node removed), when the execution context ID no longer exists, or when the target session is closing.","triggerScenarios":"Adopting an element handle right as the page navigates; the frame containing the element being detached; the execution context destroyed between finding the element and resolving it; Chrome target crash or browser shutdown mid-action.","commonSituations":"SPAs re-rendering or route-changing during element interaction; elements inside iframes that get removed; races between page.goto and element queries; long scripts where the page closes before the last action completes.","solutions":["Retry the user-level action: re-query the element and act again — the race is usually transient","Await navigations with page.waitForNavigation before touching elements","Give actions an explicit timeout budget so k6's internal retries can absorb the race","If it repeats, reduce parallelism or load on the Chrome instance"],"exampleFix":"// before\nawait page.click('#go');\nawait frameEl.click(); // races the navigation triggered by #go\n\n// after\nawait Promise.all([page.waitForNavigation(), page.click('#go')]);\nawait frameEl.click();","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"async function withRetry(fn, attempts = 3) {\n  for (let i = 0; i < attempts; i++) {\n    try { return await fn(); }\n    catch (e) {\n      if (!/resolving DOM node|navigated away|Execution context/.test(e.message) || i === attempts - 1) throw e;\n    }\n  }\n}\nawait withRetry(() => page.click('#go'));","preventionTips":["Synchronize with navigations (waitForNavigation) before interacting","Re-query elements inside the retry, not once outside it","Keep handle lifetimes short across awaits that can navigate","Give browser actions explicit timeouts so internal retries have room"],"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"}