grafana/k6 · error
extracting json value (remote object id: %v): %w
Error message
extracting json value (remote object id: %v): %w
What it means
Thrown by BaseJSHandle.JSONValue when the CDP call succeeded but parseConsoleRemoteObject cannot convert the returned remote object into a JSON string. The referenced value is not JSON-serializable from the protocol's perspective: functions, symbols, undefined, or objects the runtime refuses to serialize by value.
Source
Thrown at internal/js/modules/k6/browser/common/js_handle.go:208
}
// JSONValue returns a JSON version of this JS handle.
func (h *BaseJSHandle) JSONValue() (string, error) {
remoteObject := h.remoteObject
if remoteObject.ObjectID != "" {
var err error
action := runtime.CallFunctionOn("function() { return this; }").
WithReturnByValue(true).
WithAwaitPromise(true).
WithObjectID(h.remoteObject.ObjectID)
if remoteObject, _, err = action.Do(cdp.WithExecutor(h.ctx, h.session)); err != nil {
return "", fmt.Errorf("retrieving json value: %w", err)
}
}
res, err := parseConsoleRemoteObject(h.logger, remoteObject)
if err != nil {
return "", fmt.Errorf("extracting json value (remote object id: %v): %w", remoteObject.ObjectID, err)
}
return res, nil
}
// ObjectID returns the remote object ID.
func (h *BaseJSHandle) ObjectID() runtime.RemoteObjectID {
return h.remoteObject.ObjectID
}
View on GitHub (pinned to 93accf6570)
Solutions
- For DOM elements use element-specific accessors (textContent(), innerText(), getAttribute()) instead of jsonValue()
- Serialize inside the page: page.evaluate('el => JSON.stringify(el.dataset)') and parse the string
- If the handle comes from evaluateHandle, make the page function return plain JSON-able data (objects, arrays, primitives)
- Inspect handleotype via handle.toString() / evaluation to confirm the value type before extraction
Example fix
// before
const h = await page.evaluateHandle('() => document.querySelector("#cfg")');
const json = await h.jsonValue(); // DOM node is not JSON-serializable
// after
const json = await page.evaluate('() => JSON.stringify(cfgObject)');
const cfg = JSON.parse(json); Defensive patterns
Strategy: validation
Validate before calling
// ensure the handle refers to JSON-able data, not a DOM node or function
const desc = await handle.toString();
if (/JSHandle@node|JSHandle@function|JSHandle@symbol/.test(desc)) {
throw new Error('handle is not JSON-serializable; use page.evaluate instead');
} Try / catch
try {
return await handle.jsonValue();
} catch (e) {
if (/extracting json value/.test(e.message)) {
return JSON.parse(await page.evaluate('JSON.stringify(window.cfg)'));
}
throw e;
} Prevention
- Make evaluateHandle functions return plain objects/arrays/primitives
- Use JSON.stringify inside the page and parse the string in k6
- Use element accessors for DOM data instead of jsonValue()
When it happens
Trigger: Calling jsonValue() on a handle to a DOM element (remote object is a node, not a plain value); on a function object; on a Symbol or undefined value; on an object whose description cannot be parsed by the console-object parser.
Common situations: Assuming jsonValue() works on element handles the way it does on value handles (e.g. from page.evaluateHandle returning a primitive wrapper); evaluating handle-returning expressions that yield functions or symbols.
Related errors
- retrieving json value: %w
- element is not attached to the DOM
- dispatching element event %q: %w
- selecting text: %w
- setting input files: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/8bffc71eb2f290f4.
Report an issue: GitHub.