{"record":{"id":"67cea23683c8baf1","repo":"grafana/k6","slug":"selecthandle-dispose-w","errorCode":null,"errorMessage":"selectHandle.dispose: %w","messagePattern":"selectHandle\\.dispose: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":1756,"sourceCode":"\n\t// pack the selected <option> values inside <select> into a slice\n\toptHandles, err := selectHandle.getProperties()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"getProperties: %w\", err)\n\t}\n\tvals := make([]string, 0, len(optHandles))\n\tfor _, oh := range optHandles {\n\t\tval, err := oh.JSONValue()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"reading value: %w\", err)\n\t\t}\n\t\tvals = append(vals, val)\n\t\tif err := oh.dispose(); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"optionHandle.dispose: %w\", err)\n\t\t}\n\t}\n\tif err := selectHandle.dispose(); err != nil {\n\t\treturn nil, fmt.Errorf(\"selectHandle.dispose: %w\", err)\n\t}\n\n\treturn vals, nil\n}\n\n// SetContent replaces the entire HTML document content.\nfunc (f *Frame) SetContent(html string, _ *FrameSetContentOptions) error {\n\tf.log.Debugf(\"Frame:SetContent\", \"fid:%s furl:%q\", f.ID(), f.URL())\n\n\t// TODO(@inancgumus): Respect the FrameSetContentOptions before executing the action.\n\t// A solution is similar to the logic in `WaitForLoadState`.\n\n\tjs := `(html) => {\n\t\twindow.stop();\n\t\tdocument.open();\n\t\tdocument.write(html);\n\t\tdocument.close();\n\t}`","sourceCodeStart":1738,"sourceCodeEnd":1774,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/frame.go#L1738-L1774","documentation":"Final cleanup step of frame.selectOption: the JSHandle for the <select> element itself is disposed after all option values are read. This error means that dispose failed — the owning execution context or CDP session was destroyed before cleanup completed.","triggerScenarios":"Navigation, context switch, or page/target close between the option reads and the final dispose of the select handle.","commonSituations":"Same race as the option-handle dispose: selecting triggers navigation or the test tears down the page while selectOption is finishing; under high VU count the browser target can be recycled mid-call.","solutions":["Expect and tolerate the cleanup failure when the select intentionally navigates: verify post-state instead","Wait for load state after the change event, then retry once if needed","Avoid calling page.close() concurrently with in-flight frame actions","Keep k6 current to pick up context-lifecycle fixes"],"exampleFix":"// tolerant pattern\nlet ok = false;\ntry {\n  page.selectOption('#lang', 'en');\n  ok = true;\n} catch (e) {\n  page.waitForLoadState('load');\n  ok = page.$eval('#lang', el => el.value) === 'en';\n}\nif (!ok) throw new Error('language not selected');","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let applied = false;\ntry {\n  page.selectOption(sel, val);\n  applied = true;\n} catch (e) {\n  applied = page.$eval(sel, el => el.value) === val; // re-check on cleanup failure\n}\nif (!applied) throw new Error('selectOption did not apply');","preventionTips":["Sequence teardown after actions complete (avoid concurrent page.close)","Verify selection state independently of the call's success"],"tags":["k6","browser","jshandle","dispose","cleanup"],"backgroundTag":"js-handle-already-disposed","analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}