grafana/k6 · error

parsing inner text options: %w

Error message

parsing inner text options: %w

What it means

Thrown when locator.innerText(opts) cannot parse its options into FrameInnerTextOptions (embeds FrameBaseOptions: strict boolean, timeout number in ms). The mapping wraps the cause as 'parsing inner text options: %w'. The current parser is lenient — it iterates object keys, coerces values and ignores unknown ones — so in practice this error means the second argument was not a usable options object.

Source

Thrown at internal/js/modules/k6/browser/browser/locator_mapping.go:316

			return mapLocator(vu, lo.Locator(selector, parseLocatorOptions(rt, opts)))
		},
		"frameLocator": func(selector string) *sobek.Object {
			mfl := mapFrameLocator(vu, lo.FrameLocator(selector))
			return rt.ToValue(mfl).ToObject(rt)
		},
		"innerHTML": func(opts sobek.Value) (*sobek.Promise, error) {
			copts := common.NewFrameInnerHTMLOptions(lo.Timeout())
			if err := copts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing inner HTML options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return lo.InnerHTML(copts) //nolint:wrapcheck
			}), nil
		},
		"innerText": func(opts sobek.Value) (*sobek.Promise, error) {
			copts := common.NewFrameInnerTextOptions(lo.Timeout())
			if err := copts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing inner text options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return lo.InnerText(copts) //nolint:wrapcheck
			}), nil
		},
		"last": func() *sobek.Object {
			ml := mapLocator(vu, lo.Last())
			return rt.ToValue(ml).ToObject(rt)
		},
		"nth": func(nth int) *sobek.Object {
			ml := mapLocator(vu, lo.Nth(nth))
			return rt.ToValue(ml).ToObject(rt)
		},
		"textContent": func(opts sobek.Value) (*sobek.Promise, error) {
			copts := common.NewFrameTextContentOptions(lo.Timeout())
			if err := copts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing text content options: %w", err)
			}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Call innerText() bare, or pass { timeout: <number-ms> }
  2. Verify the second parameter is a plain object literal, not a string/number/array
  3. Spell keys exactly: strict, timeout
  4. Re-run with the latest k6 browser module, which ignores/coerces bad keys instead of failing

Example fix

// before
const text = await page.locator('h1').innerText('10s');

// after
const text = await page.locator('h1').innerText({ timeout: 10000 });
Defensive patterns

Strategy: validation

Validate before calling

function assertBaseOpts(method, opts) {
  if (opts === null || opts === undefined) return;
  if (typeof opts !== 'object' || Array.isArray(opts)) {
    throw new TypeError(`${method} options must be a plain object, got ${typeof opts}`);
  }
  if ('timeout' in opts && typeof opts.timeout !== 'number') {
    throw new TypeError(`${method} timeout must be a number (ms)`);
  }
}
assertBaseOpts('innerText', opts);

Type guard

function isLocatorBaseOptions(v) {
  if (v === null || v === undefined) return true;
  if (typeof v !== 'object' || Array.isArray(v)) return false;
  return (v.timeout === undefined || typeof v.timeout === 'number') &&
         (v.strict === undefined || typeof v.strict === 'boolean');
}

Try / catch

try {
  const text = await locator.innerText(opts);
} catch (e) {
  if (/parsing inner text options/.test(String(e.message))) {
    throw new Error(`Bad innerText options: ${JSON.stringify(opts)}`);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling locator.innerText(30000) or innerText('30s') with a scalar in the opts slot; passing a non-plain-object (e.g. a function or array) as options; wrong-typed strict/timeout fields on k6 builds that validate types strictly.

Common situations: Scripts migrated from Puppeteer where waitForTimeout-style string durations are common; passing the same options object reused from a click() call into innerText(); typos like { timout: 5000 } that strict parsers reject.

Related errors


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