{"record":{"id":"602d9bd63a713275","repo":"grafana/k6","slug":"disposing-property-while-querying-all-selectors-q","errorCode":null,"errorMessage":"disposing property while querying all selectors %q: %w","messagePattern":"disposing property while querying all selectors %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/js/modules/k6/browser/common/element_handle.go","lineNumber":1312,"sourceCode":"\t}\n\n\ttype indexedElem struct {\n\t\tindex int\n\t\telem  *ElementHandle\n\t}\n\n\tindexedElems := make([]indexedElem, 0, len(props))\n\tfor key, prop := range props {\n\t\tif el := prop.AsElement(); el != nil {\n\t\t\t// DOM elements are stored with numeric indices (\"0\", \"1\", \"2\", ...)\n\t\t\t// per JavaScript's array-like object specification.\n\t\t\tidx, err := strconv.Atoi(key)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"parsing element index %q for selector %q: %w\", key, selector, err)\n\t\t\t}\n\t\t\tindexedElems = append(indexedElems, indexedElem{index: idx, elem: el})\n\t\t} else if err := prop.Dispose(); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"disposing property while querying all selectors %q: %w\", selector, err)\n\t\t}\n\t}\n\n\tslices.SortFunc(indexedElems, func(a, b indexedElem) int {\n\t\treturn cmp.Compare(a.index, b.index)\n\t})\n\n\tels := make([]*ElementHandle, 0, len(indexedElems))\n\tfor _, ie := range indexedElems {\n\t\tels = append(els, ie.elem)\n\t}\n\n\treturn els, nil\n}\n\n// SetChecked checks or unchecks an element.\nfunc (h *ElementHandle) SetChecked(checked bool, opts *ElementHandleSetCheckedOptions) error {\n\tsetChecked := func(apiCtx context.Context, handle *ElementHandle, p *Position) (any, error) {","sourceCodeStart":1294,"sourceCodeEnd":1330,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/element_handle.go#L1294-L1330","documentation":"In queryAll's property loop, non-element properties are disposed as cleanup; one of those Dispose calls failed (element_handle.go:1312). Like the other deferred-dispose errors, it means the target/context went away mid-operation; the operation was already failing or about to return.","triggerScenarios":"Browser page/target closed or context destroyed by navigation while $$ was iterating result properties (each non-element property gets disposed immediately).","commonSituations":"Long result lists being disposed when k6 ends the iteration and closes the browser; navigation racing a bulk scrape.","solutions":["Fix the underlying timing: wait for stable state before $$","Don't close the browser while scrape promises are in flight","Ignore when the target is already intentionally closed","Keep result sets smaller (narrower selector) to shrink the dispose window"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { return await el.$$(sel); }\ncatch (e) { if (/disposing property while querying/.test(e.message) && targetWasClosing) return []; throw e; }","preventionTips":["Finish scrapes before closing the browser","Narrow selectors to shrink the dispose window","Stabilize navigation before bulk queries"],"tags":["browser","cleanup","disposal","race-condition"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}