grafana/k6 · error

%w

Error message

%w

What it means

Returned by wait when the browser operation's context is canceled or its deadline expires before the timer elapses; it wraps the context error (context.Canceled or context.DeadlineExceeded) so callers can identify cancellation rather than a timeout of the operation itself.

Solutions

  1. Check errors.Is(err, context.Canceled) or errors.Is(err, context.DeadlineExceeded) to distinguish cancellation from other failures
  2. Ensure the k6 iteration/browser context timeout is large enough for the delay passed to wait
  3. Avoid calling keyboard APIs with delays that exceed the remaining context lifetime
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/common/keyboard.go:347 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/dd7112ef1e1035f0. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/common/keyboard.go:347

				return fmt.Errorf("pressing key: %w", err)
			}
			continue
		}
		if err := k.insertText(string(c)); err != nil {
			return fmt.Errorf("inserting text: %w", err)
		}
	}
	return nil
}

func wait(ctx context.Context, delay int64) error {
	t := time.NewTimer(time.Duration(delay) * time.Millisecond)
	select {
	case <-ctx.Done():
		if !t.Stop() {
			<-t.C
		}
		return fmt.Errorf("%w", ContextErr(ctx))
	case <-t.C:
	}

	return nil
}

View on GitHub (pinned to 01ffac6f24)