grafana/k6 · error

parsing getAttribute options

Error message

parsing getAttribute options: %w

What it means

Thrown when the options argument to `frame.getAttribute(selector, name, opts)` fails to parse into FrameBaseOptions (keys: `strict`, `timeout` in ms). The error is raised synchronously before the promise is created, so it appears as a JS exception at the call site, not a rejected promise. In the current code the Parse loop is coercive and cannot fail; this wrapper is defensive.

Solutions

  1. Use only { strict, timeout } with numeric timeout in milliseconds
  2. Check the wrapped cause in the error chain (fmt.Errorf %w) to see what the parser actually rejected
  3. Call the method without opts or with undefined/null — both are accepted (IsNullish check)

Example fix

// before
const v = await frame.getAttribute('#a', 'href', { timeout: '5s' });

// after
const v = await frame.getAttribute('#a', 'href', { timeout: 5000 });
Defensive patterns

Strategy: try-catch

Validate before calling

const opts = { timeout: 5000, strict: false };
const extra = Object.keys(opts).filter(k => !['strict', 'timeout'].includes(k));
if (extra.length) console.warn('getAttribute ignores unknown keys:', extra);

Type guard

function isFrameBaseOptions(o) {
  return o == null || (
    typeof o === 'object' &&
    (o.timeout === undefined || typeof o.timeout === 'number') &&
    (o.strict === undefined || typeof o.strict === 'boolean')
  );
}

Try / catch

try {
  const href = await frame.getAttribute('#a', 'href', opts);
} catch (e) {
  if (String(e).includes('parsing getAttribute options')) { /* fix opts and retry */ } else { throw e; }
}

Prevention

When it happens

Trigger: Calling `frame.getAttribute(sel, name, opts)` with a non-object or type-invalid opts under a k6 version whose Parse validates; today unknown keys are skipped and `strict`/`timeout` are coerced, so no runtime path produces this error.

Common situations: Copy-pasting Playwright snippets with unsupported keys; passing a string duration for timeout, which silently coerces to 0ms rather than erroring.

Related errors


AI-assisted analysis of grafana/k6@8d06114777 (2026-09-14). Data as JSON: /api/errors/67249b839ce37117. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/browser/frame_mapping.go:126

				return nil, fmt.Errorf("parsing focus options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, f.Focus(selector, popts) //nolint:wrapcheck
			}), nil
		},
		"frameElement": func() *sobek.Promise {
			return promise(vu, func() (any, error) {
				fe, err := f.FrameElement()
				if err != nil {
					return nil, err //nolint:wrapcheck
				}
				return mapElementHandle(vu, fe), nil
			})
		},
		"getAttribute": func(selector, name string, opts sobek.Value) (*sobek.Promise, error) {
			popts := common.NewFrameBaseOptions(f.Timeout())
			if err := parseFrameBaseOptions(popts, rt, opts); err != nil {
				return nil, fmt.Errorf("parsing getAttribute options: %w", err)
			}
			return promise(vu, func() (any, error) {
				s, ok, err := f.GetAttribute(selector, name, popts)
				if err != nil {
					return nil, err //nolint:wrapcheck
				}
				if !ok {
					return nil, nil //nolint:nilnil
				}
				return s, nil
			}), nil
		},
		"getByAltText": func(alt sobek.Value, opts sobek.Value) (*sobek.Object, error) {
			if k6common.IsNullish(alt) {
				return nil, errors.New("missing required argument 'altText'")
			}
			palt, popts := parseGetByBaseOptions(vu.Context(), alt, false, opts)

View on GitHub (pinned to 8d06114777)