{"record":{"id":"aa381477f6566271","repo":"grafana/k6","slug":"disposing-element-with-id-s-w","errorCode":null,"errorMessage":"disposing element with ID %s: %w","messagePattern":"disposing element with ID (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/js/modules/k6/browser/common/js_handle.go","lineNumber":114,"sourceCode":"\n\t// We do not want to return an error when the error is a closed\n\t// context. The reason the context would be closed is due to the\n\t// iteration ending and therefore the associated browser and its assets\n\t// will be automatically deleted.\n\tif errors.Is(err, context.Canceled) {\n\t\th.logger.Debugf(\"BaseJSHandle:Dispose\", \"%v\", err)\n\t\treturn nil\n\t}\n\t// The following error indicates that the object we're trying to release\n\t// cannot be found, which would mean that the object has already been\n\t// removed/deleted. This can occur when a navigation occurs, usually when\n\t// a page contains an iframe.\n\tif strings.Contains(err.Error(), \"Cannot find context with specified id\") {\n\t\th.logger.Debugf(\"BaseJSHandle:Dispose\", \"%v\", err)\n\t\treturn nil\n\t}\n\n\treturn fmt.Errorf(\"disposing element with ID %s: %w\", h.remoteObject.ObjectID, err)\n}\n\n// dispose sends a command to the browser to release the remote object.\nfunc (h *BaseJSHandle) dispose() error {\n\tif h.disposed {\n\t\treturn nil\n\t}\n\th.disposed = true\n\tif h.remoteObject.ObjectID == \"\" {\n\t\treturn nil\n\t}\n\tact := runtime.ReleaseObject(h.remoteObject.ObjectID)\n\tif err := act.Do(cdp.WithExecutor(h.ctx, h.session)); err != nil {\n\t\treturn fmt.Errorf(\"disposing element with ID %s: %w\",\n\t\t\th.remoteObject.ObjectID, err)\n\t}\n\n\treturn nil","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/js_handle.go#L96-L132","documentation":"BaseJSHandle.Dispose releases the handle's remote object via Runtime.releaseObject. Two benign failures are detected by message and swallowed: 'Execution context was destroyed' and 'Cannot find context with specified id' (the object is already gone, typically after navigation or with iframes). This error therefore means ReleaseObject failed for some other reason and the object could not be released.","triggerScenarios":"Calling handle.dispose() (directly or via disposal paths like Frame cleanup) when the CDP call fails with a non-benign error: the DevTools session dropped, the browser died, or the object belongs to a context that was replaced but the error text differs from the swallowed cases.","commonSituations":"Disposing element/JS handles late in the iteration; iframe-heavy pages where contexts churn during navigation; browser disconnect during teardown; parallel load causing transport failures.","solutions":["Dispose handles promptly, before navigation destroys their execution context","During teardown after the browser is going away, treat this as non-fatal and log it rather than failing the test","Check for concurrent CDP errors to identify a dropped connection and fix that root cause","Upgrade k6: dispose error handling has been refined over releases"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await handle.dispose(); }\ncatch (e) {\n  if (/disposing element with ID/.test(String(e.message))) { /* log and continue; object leak is harmless short-term */ }\n  else throw e;\n}","preventionTips":["Dispose handles before navigating away from their context","Treat dispose failures during final teardown as non-fatal","Investigate accompanying CDP errors to find connection drops"],"tags":["browser","js-handle","lifecycle","cdp","cleanup"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}