grafana/k6 · error

disposing property while querying all selectors

Error message

disposing property while querying all selectors %q: %w

What it means

Produced in ElementHandle.queryAll while iterating result properties: when a property is not an element, it is disposed eagerly to avoid leaks; if that Dispose call fails, the error is wrapped this way and returned. Typical cause is the execution context being destroyed mid-iteration (navigation/close), making the property handle already invalid.

Solutions

  1. Avoid navigating or closing the page while QueryAll runs
  2. Treat as transient if it coincides with navigation; retry the query
  3. Check for browser crashes if it happens consistently
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/common/element_handle.go:1312 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at internal/js/modules/k6/browser/common/element_handle.go:1312

	}

	type indexedElem struct {
		index int
		elem  *ElementHandle
	}

	indexedElems := make([]indexedElem, 0, len(props))
	for key, prop := range props {
		if el := prop.AsElement(); el != nil {
			// DOM elements are stored with numeric indices ("0", "1", "2", ...)
			// per JavaScript's array-like object specification.
			idx, err := strconv.Atoi(key)
			if err != nil {
				return nil, fmt.Errorf("parsing element index %q for selector %q: %w", key, selector, err)
			}
			indexedElems = append(indexedElems, indexedElem{index: idx, elem: el})
		} else if err := prop.Dispose(); err != nil {
			return nil, fmt.Errorf("disposing property while querying all selectors %q: %w", selector, err)
		}
	}

	slices.SortFunc(indexedElems, func(a, b indexedElem) int {
		return cmp.Compare(a.index, b.index)
	})

	els := make([]*ElementHandle, 0, len(indexedElems))
	for _, ie := range indexedElems {
		els = append(els, ie.elem)
	}

	return els, nil
}

// SetChecked checks or unchecks an element.
func (h *ElementHandle) SetChecked(checked bool, opts *ElementHandleSetCheckedOptions) error {
	setChecked := func(apiCtx context.Context, handle *ElementHandle, p *Position) (any, error) {

View on GitHub (pinned to 3fcf5388d7)