{"record":{"id":"dececde1a990f9d6","repo":"grafana/k6","slug":"optionhandle-dispose-w","errorCode":null,"errorMessage":"optionHandle.dispose: %w","messagePattern":"optionHandle\\.dispose: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":1752,"sourceCode":"\tselectHandle, ok := v.(jsHandle)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected select element type %T\", v)\n\t}\n\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();","sourceCodeStart":1734,"sourceCodeEnd":1770,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/frame.go#L1734-L1770","documentation":"In frame.selectOption, after reading each selected option's value, its JSHandle is disposed to free the remote object. This error means dispose() failed for one option handle — usually because the execution context or session it belonged to was already destroyed (navigation, page close) or the object was already gone.","triggerScenarios":"The page navigates or the context dies between JSONValue() and dispose() of an option handle; the handle's remote object no longer exists.","commonSituations":"Select onChange navigation (locale pickers, auto-submitting forms); heavy DOM churn right after selection; teardown racing the call.","solutions":["Treat it as a symptom of the navigation race: wait for the new document and verify selection separately","Retry selectOption once the page is stable","Disable auto-navigation on select in the app under test when feasible","Upgrade k6 — dispose failures after context loss have been smoothed over time"],"exampleFix":"// before\nconst vals = page.selectOption('#lang', 'en');\n\n// after\nlet vals = [];\ntry {\n  vals = page.selectOption('#lang', 'en');\n} catch (e) {\n  console.log(`selectOption cleanup raced navigation: ${e}`);\n  page.waitForLoadState('load');\n  vals = [page.$eval('#lang', el => el.value)];\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  page.selectOption(sel, val);\n} catch (e) {\n  // cleanup raced navigation — verify the outcome instead of failing\n  page.waitForLoadState('load');\n  if (page.$eval(sel, el => el.value) !== val) throw e;\n}","preventionTips":["Treat dispose-stage failures as navigation-race symptoms; verify post-state","Don't tear down the page until frame actions return"],"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"}