grafana/k6 · warning

optionHandle.dispose

Error message

optionHandle.dispose: %w

What it means

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.

Solutions

  1. Treat it as a symptom of the navigation race: wait for the new document and verify selection separately
  2. Retry selectOption once the page is stable
  3. Disable auto-navigation on select in the app under test when feasible
  4. Upgrade k6 — dispose failures after context loss have been smoothed over time

Example fix

// before
const vals = page.selectOption('#lang', 'en');

// after
let vals = [];
try {
  vals = page.selectOption('#lang', 'en');
} catch (e) {
  console.log(`selectOption cleanup raced navigation: ${e}`);
  page.waitForLoadState('load');
  vals = [page.$eval('#lang', el => el.value)];
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
  page.selectOption(sel, val);
} catch (e) {
  // cleanup raced navigation — verify the outcome instead of failing
  page.waitForLoadState('load');
  if (page.$eval(sel, el => el.value) !== val) throw e;
}

Prevention

When it happens

Trigger: The page navigates or the context dies between JSONValue() and dispose() of an option handle; the handle's remote object no longer exists.

Common situations: Select onChange navigation (locale pickers, auto-submitting forms); heavy DOM churn right after selection; teardown racing the call.

Related errors


AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18). Data as JSON: /api/errors/dececde1a990f9d6. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/common/frame.go:1752

	selectHandle, ok := v.(jsHandle)
	if !ok {
		return nil, fmt.Errorf("unexpected select element type %T", v)
	}

	// pack the selected <option> values inside <select> into a slice
	optHandles, err := selectHandle.getProperties()
	if err != nil {
		return nil, fmt.Errorf("getProperties: %w", err)
	}
	vals := make([]string, 0, len(optHandles))
	for _, oh := range optHandles {
		val, err := oh.JSONValue()
		if err != nil {
			return nil, fmt.Errorf("reading value: %w", err)
		}
		vals = append(vals, val)
		if err := oh.dispose(); err != nil {
			return nil, fmt.Errorf("optionHandle.dispose: %w", err)
		}
	}
	if err := selectHandle.dispose(); err != nil {
		return nil, fmt.Errorf("selectHandle.dispose: %w", err)
	}

	return vals, nil
}

// SetContent replaces the entire HTML document content.
func (f *Frame) SetContent(html string, _ *FrameSetContentOptions) error {
	f.log.Debugf("Frame:SetContent", "fid:%s furl:%q", f.ID(), f.URL())

	// TODO(@inancgumus): Respect the FrameSetContentOptions before executing the action.
	// A solution is similar to the logic in `WaitForLoadState`.

	js := `(html) => {
		window.stop();

View on GitHub (pinned to 3fcf5388d7)