grafana/k6 · error

invalid WebSocket tags option

Error message

invalid WebSocket tags option: %w

What it means

Returned by buildParams while parsing the options object of new WebSocket(url, params): the `tags` entry failed common.ApplyCustomUserTags, meaning the tags value is not a valid tags object (not an object, or contains values that cannot be treated as tag strings). The wrapped error carries the specifics; the connection is never attempted.

Solutions

  1. Pass tags as a plain object of string values: new WebSocket(url, { tags: { env: 'staging' } })
  2. Omit the tags key if no custom tags are needed
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/js/modules/k6/websockets/params.go:59 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/2c0826fe3c5186f8. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/websockets/params.go:59

	params := raw.ToObject(rt)
	for _, k := range params.Keys() {
		switch k {
		case "headers":
			headersV := params.Get(k)
			if common.IsNullish(headersV) {
				continue
			}
			headersObj := headersV.ToObject(rt)
			if headersObj == nil {
				continue
			}
			for _, key := range headersObj.Keys() {
				parsed.headers.Set(key, headersObj.Get(key).String())
			}
		case "tags":
			if err := common.ApplyCustomUserTags(rt, parsed.tagsAndMeta, params.Get(k)); err != nil {
				return nil, fmt.Errorf("invalid WebSocket tags option: %w", err)
			}
		case "jar":
			jarV := params.Get(k)
			if common.IsNullish(jarV) {
				continue
			}
			if v, ok := jarV.Export().(*httpModule.CookieJar); ok {
				parsed.cookieJar = v.Jar
			}
		case "compression":
			// deflate compression algorithm is supported - as defined in RFC7692
			// compression here relies on the implementation in gorilla/websocket package, usage is
			// experimental and may result in decreased performance. package supports
			// only "no context takeover" scenario

			algoString := strings.TrimSpace(params.Get(k).ToString().String())
			if algoString != "deflate" {
				return nil, fmt.Errorf("unsupported compression algorithm '%s', supported algorithm is 'deflate'", algoString)

View on GitHub (pinned to 01ffac6f24)