grafana/k6 · error

unmarshaling DOM element state

Error message

unmarshaling DOM element state: %w

What it means

Returned by DOMElementState.UnmarshalJSON when the raw JSON for a DOM element state is not a valid JSON string (e.g. a number, object, or malformed JSON). The state field is expected as a quoted string like "attached", "detached", "visible" or "hidden"; anything else fails json.Unmarshal into the string sink.

Solutions

  1. Pass the state option as one of the strings: attached, detached, visible, hidden
  2. Do not pass numbers, objects, or unquoted identifiers as state
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/common/frame.go:72 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/48db9741627a6c49. Report an issue: GitHub.

Appendix: source

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

func DOMElementStateIDFromString(format string) (DOMElementState, bool) {
	id, exists := domElementStateToID[format]
	return id, exists
}

// MarshalJSON marshals the enum as a quoted JSON string.
func (s DOMElementState) MarshalJSON() ([]byte, error) {
	buffer := bytes.NewBufferString(`"`)
	buffer.WriteString(domElementStateToString[s])
	buffer.WriteString(`"`)
	return buffer.Bytes(), nil
}

// UnmarshalJSON unmarshals a quoted JSON string to the enum value.
func (s *DOMElementState) UnmarshalJSON(b []byte) error {
	var j string
	err := json.Unmarshal(b, &j)
	if err != nil {
		return fmt.Errorf("unmarshaling DOM element state: %w", err)
	}
	// Note that if the string cannot be found then it will be set to the zero value.
	*s = domElementStateToID[j]
	return nil
}

// Frame represents a frame in an HTML document.
type Frame struct {
	BaseEventEmitter

	ctx         context.Context
	page        *Page
	manager     *FrameManager
	parentFrame *Frame

	childFramesMu sync.RWMutex
	childFrames   map[*Frame]bool

View on GitHub (pinned to 3fcf5388d7)