grafana/k6 · error

extracting value from remote object with ID %s: %w

Error message

extracting value from remote object with ID %s: %w

What it means

After a returnByValue evaluation succeeds, k6 unwraps the remote object's value (valueFromRemoteObject). If that unwrap fails — the object carries a value that cannot be decoded, or the object was released between evaluation and extraction — this error reports the failing object ID. It is a lower-level decode failure, distinct from page exceptions (which arrive via exceptionDetails).

Source

Thrown at internal/js/modules/k6/browser/common/execution_context.go:238

		e.logger.Debugf("ExecutionContext:eval", "Unexpected DevTools server error: %v", err)
		return nil, err
	}
	if exceptionDetails != nil {
		return nil, fmt.Errorf("%s", parseExceptionDetails(exceptionDetails))
	}
	var res any
	if remoteObject == nil {
		e.logger.Debugf(
			"ExecutionContext:eval",
			"sid:%s stid:%s fid:%s ectxid:%d furl:%q remoteObject is nil",
			e.sid, e.stid, e.fid, e.id, e.furl)
		return res, nil
	}

	if opts.returnByValue {
		res, err = valueFromRemoteObject(apiCtx, remoteObject)
		if err != nil {
			return nil, fmt.Errorf(
				"extracting value from remote object with ID %s: %w",
				remoteObject.ObjectID, err)
		}
	} else if remoteObject.ObjectID != "" {
		// Note: we don't use the passed in apiCtx here as it could be tied to a timeout
		res = NewJSHandle(e.ctx, e.session, e, e.frame, remoteObject, e.logger)
	}

	return res, nil
}

// Based on: https://github.com/microsoft/playwright/blob/master/src/server/injected/injectedScript.ts
//
//go:embed js/injected_script.js
var injectedScriptSource string

//nolint:gochecknoglobals
var injectedScriptSourceWithSourceURL = `(() => {` + injectedScriptSource + `; return new InjectedScript();})()` +

View on GitHub (pinned to 93accf6570)

Solutions

  1. Return plain, small, JSON-friendly values from evaluate
  2. For large or complex results, use evaluateHandle and then jsonValue() instead of by-value returns
  3. Retry once — release races are transient
  4. If it persists with well-formed values, report it as a k6 browser module issue with a minimal reproducer

Example fix

// before
const cfg = await page.evaluate(() => window.__hugeConfigObject);

// after
const h = await page.evaluateHandle(() => window.__hugeConfigObject);
const cfg = await h.jsonValue();
Defensive patterns

Strategy: try-catch

Try / catch

try {
  v = await page.evaluate(fn);
} catch (e) {
  if (/extracting value from remote object/.test(e.message)) {
    const h = await page.evaluateHandle(fn);
    v = await h.jsonValue();
  } else throw e;
}

Prevention

When it happens

Trigger: Evaluating expressions that return values Chromium marks unserializable in ways the wrapper cannot decode; objects released/disposed during navigation races between evaluation and value extraction; returning very large or deeply nested structures by value.

Common situations: Returning BigInts or huge structures from evaluate; races where navigation invalidates the remote object before k6 reads it.

Related errors


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