{"record":{"id":"8bffc71eb2f290f4","repo":"grafana/k6","slug":"extracting-json-value-remote-object-id-v-w","errorCode":null,"errorMessage":"extracting json value (remote object id: %v): %w","messagePattern":"extracting json value \\(remote object id: (.+?)\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/js_handle.go","lineNumber":208,"sourceCode":"}\n\n// JSONValue returns a JSON version of this JS handle.\nfunc (h *BaseJSHandle) JSONValue() (string, error) {\n\tremoteObject := h.remoteObject\n\tif remoteObject.ObjectID != \"\" {\n\t\tvar err error\n\t\taction := runtime.CallFunctionOn(\"function() { return this; }\").\n\t\t\tWithReturnByValue(true).\n\t\t\tWithAwaitPromise(true).\n\t\t\tWithObjectID(h.remoteObject.ObjectID)\n\t\tif remoteObject, _, err = action.Do(cdp.WithExecutor(h.ctx, h.session)); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"retrieving json value: %w\", err)\n\t\t}\n\t}\n\n\tres, err := parseConsoleRemoteObject(h.logger, remoteObject)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"extracting json value (remote object id: %v): %w\", remoteObject.ObjectID, err)\n\t}\n\n\treturn res, nil\n}\n\n// ObjectID returns the remote object ID.\nfunc (h *BaseJSHandle) ObjectID() runtime.RemoteObjectID {\n\treturn h.remoteObject.ObjectID\n}\n","sourceCodeStart":190,"sourceCodeEnd":218,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/js_handle.go#L190-L218","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nconst h = await page.evaluateHandle('() => document.querySelector(\"#cfg\")');\nconst json = await h.jsonValue();   // DOM node is not JSON-serializable\n\n// after\nconst json = await page.evaluate('() => JSON.stringify(cfgObject)');\nconst cfg = JSON.parse(json);","handlingStrategy":"validation","validationCode":"// ensure the handle refers to JSON-able data, not a DOM node or function\nconst desc = await handle.toString();\nif (/JSHandle@node|JSHandle@function|JSHandle@symbol/.test(desc)) {\n  throw new Error('handle is not JSON-serializable; use page.evaluate instead');\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await handle.jsonValue();\n} catch (e) {\n  if (/extracting json value/.test(e.message)) {\n    return JSON.parse(await page.evaluate('JSON.stringify(window.cfg)'));\n  }\n  throw e;\n}","preventionTips":["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()"],"tags":["browser","js-handle","serialization","dom"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}