{"record":{"id":"1f3c82f6fee65060","repo":"microsoft/playwright","slug":"cannot-serialize-result-object-reference-chain-is-1f3c82","errorCode":null,"errorMessage":"Cannot serialize result: object reference chain is too long.","messagePattern":"Cannot serialize result: object reference chain is too long\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/server/chromium/crExecutionContext.ts","lineNumber":104,"sourceCode":"      result.set(property.name, createHandle(object._context, property.value));\n    }\n    return result;\n  }\n\n  async releaseHandle(handle: js.JSHandle): Promise<void> {\n    if (!handle._objectId)\n      return;\n    await releaseObject(this._client, handle._objectId);\n  }\n\n  shouldPrependErrorPrefix(): boolean {\n    return false;\n  }\n}\n\nfunction rewriteError(error: Error): Protocol.Runtime.evaluateReturnValue {\n  if (error.message.includes('Object reference chain is too long') || error.message.includes('CBOR: stack limit exceeded'))\n    throw new Error('Cannot serialize result: object reference chain is too long.');\n  if (error.message.includes('Object couldn\\'t be returned by value'))\n    return { result: { type: 'undefined' } };\n  if (error.message.includes('Promise was collected'))\n    throw new Error('Resulting promise was garbage collected.');\n\n  if (error instanceof TypeError && error.message.startsWith('Converting circular structure to JSON'))\n    rewriteErrorMessage(error, error.message + ' Are you passing a nested JSHandle?');\n  if (!js.isJavaScriptErrorInEvaluate(error) && !isSessionClosedError(error))\n    throw new Error('Execution context was destroyed, most likely because of a navigation.');\n  throw error;\n}\n\nfunction potentiallyUnserializableValue(remoteObject: Protocol.Runtime.RemoteObject): any {\n  const value = remoteObject.value;\n  const unserializableValue = remoteObject.unserializableValue;\n  return unserializableValue ? js.parseUnserializableValue(unserializableValue) : value;\n}\n","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/server/chromium/crExecutionContext.ts#L86-L122","documentation":"Rewritten in rewriteError() (crExecutionContext.ts:104) when the underlying CDP error message contains 'Object reference chain is too long' or 'CBOR: stack limit exceeded'. The protocol serializer hit its reference-depth limit while materializing the result of an evaluate.","triggerScenarios":"page.evaluate(() => hugeOrDeeplyNestedObject); returning window, document, a framework's component tree, or a cyclic graph by value; jsHandle.getProperty chains projected back as values.","commonSituations":"Returning the whole Vue/React root from evaluate; returning large state stores; debugging helpers that dump nested configs.","solutions":["Project the data to a small/plain shape inside the page before returning.","Return a handle via page.evaluateHandle(() => big) instead of by-value evaluate.","If you need fields, read them individually with handle.getProperty and jsonValue on primitives."],"exampleFix":"// before\nconst state = await page.evaluate(() => window.__bigStore__);\n// after\nconst handle = await page.evaluateHandle(() => window.__bigStore__);\nconst summary = await handle.evaluate(s => ({ users: s.users.length, ready: s.ready }));","handlingStrategy":"validation","validationCode":"// Project to a small shape inside the page; fall back to a handle for large graphs.\nconst small = await page.evaluate(() => {\n  const s = (window as any).__bigStore__;\n  return { count: s?.items?.length ?? 0, ready: !!s?.ready };\n});\n// Only if you really need the whole object:\nconst handle = await page.evaluateHandle(() => (window as any).__bigStore__);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never return window/document/large framework state by value from evaluate.","Prefer evaluateHandle for big objects and read fields individually.","Strip to JSON-safe primitives before crossing the protocol boundary."],"tags":["evaluate","serialization","cdp","chromium"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}