grafana/k6 · error

parsing scrollIntoViewIfNeeded options: %w

Error message

parsing scrollIntoViewIfNeeded options: %w

What it means

Thrown synchronously by ElementHandle.scrollIntoViewIfNeeded() when its options fail to parse. The method parses common.ElementHandleBaseOptions (force, noWaitAfter, timeout), whose Parse in common/element_handle_options.go is lenient coercion and always returns nil, making this wrap defensive and effectively unreachable in current k6.

Source

Thrown at internal/js/modules/k6/browser/browser/element_handle_mapping.go:193

			if err := popts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing element handle screenshot options: %w", err)
			}

			return promise(vu, func() (any, error) {
				bb, err := eh.Screenshot(popts, vu.filePersister)
				if err != nil {
					return nil, err //nolint:wrapcheck
				}

				ab := rt.NewArrayBuffer(bb)

				return &ab, nil
			}), nil
		},
		"scrollIntoViewIfNeeded": func(opts sobek.Value) (*sobek.Promise, error) {
			popts := common.NewElementHandleBaseOptions(eh.DefaultTimeout())
			if err := popts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing scrollIntoViewIfNeeded options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, eh.ScrollIntoViewIfNeeded(popts) //nolint:wrapcheck
			}), nil
		},
		"selectOption": func(values sobek.Value, opts sobek.Value) (*sobek.Promise, error) {
			convValues, err := ConvertSelectOptionValues(vu.Runtime(), values)
			if err != nil {
				return nil, fmt.Errorf("parsing select options values: %w", err)
			}
			popts := common.NewElementHandleBaseOptions(eh.DefaultTimeout())
			if err := popts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing selectOption options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return eh.SelectOption(convValues, popts) //nolint:wrapcheck
			}), nil
		},

View on GitHub (pinned to 93accf6570)

Solutions

  1. Use only { force, noWaitAfter, timeout } with a numeric millisecond timeout
  2. Do not pass block/inline alignment options; they are unsupported for this API in k6
  3. Upgrade k6 if the message appears, since current Parse cannot fail
  4. Read the wrapped cause after the colon to find the failing field

Example fix

// before
await el.scrollIntoViewIfNeeded({ block: 'center', timeout: '5s' });

// after
await el.scrollIntoViewIfNeeded({ timeout: 5000 });
Defensive patterns

Strategy: try-catch

Validate before calling

const ALLOWED = new Set(['force', 'noWaitAfter', 'timeout']);
const bad = Object.keys(opts || {}).filter(k => !ALLOWED.has(k));
if (bad.length) console.warn(`scrollIntoViewIfNeeded(): unsupported options ignored: ${bad.join(', ')}`);
if (opts?.timeout !== undefined && !Number.isFinite(Number(opts.timeout))) {
  throw new Error('scrollIntoViewIfNeeded(): timeout must be ms number');
}

Type guard

function isScrollOpts(o) {
  if (o == null) return true;
  return (o.force === undefined || typeof o.force === 'boolean') &&
         (o.noWaitAfter === undefined || typeof o.noWaitAfter === 'boolean') &&
         (o.timeout === undefined || Number.isFinite(o.timeout));
}

Try / catch

try {
  await el.scrollIntoViewIfNeeded(opts);
} catch (e) {
  if (/parsing scrollIntoViewIfNeeded options/.test(String(e.message))) {
    console.log(`fix options: ${e.message}`);
  } else throw e; // e.g. timeout waiting for visibility happens inside the promise
}

Prevention

When it happens

Trigger: In current code none: any values for force/noWaitAfter/timeout coerce and unknown keys are ignored. Older xk6-browser builds with structural base-option parsing could raise it.

Common situations: Porting Playwright scripts that pass extra scroll options (block/inline are NOT supported here and are silently ignored, unlike Playwright's scrollIntoViewIfNeeded); mistaking a later 'element is not in the viewport' timeout inside the promise for this parse error.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/80c00a268b1f8bdd. Report an issue: GitHub.