{"record":{"id":"064bc9744e18c3e7","repo":"jackwener/OpenCLI","slug":"notebooklm-rpc-transport-returned-malformed-respon","errorCode":null,"errorMessage":"NotebookLM RPC transport returned malformed response fields","messagePattern":"NotebookLM RPC transport returned malformed response fields","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/notebooklm/rpc.js","lineNumber":214,"sourceCode":"      body: request.method === 'GET' ? undefined : request.body,\n      credentials: 'include',\n    });\n\n    return {\n      ok: response.ok,\n      status: response.status,\n      body: await response.text(),\n      requestUrl,\n      finalUrl: response.url,\n    };\n  })()`);\n    }\n    catch (error) {\n        rethrowNotebooklmTransport(error, 'RPC transport');\n    }\n    const raw = requireNotebooklmObject(unwrapNotebooklmEvaluateResult(evaluated), 'RPC transport');\n    if (typeof raw.ok !== 'boolean' || !Number.isInteger(raw.status) || typeof raw.body !== 'string' || typeof raw.requestUrl !== 'string' || typeof raw.finalUrl !== 'string') {\n        throw new CommandExecutionError('NotebookLM RPC transport returned malformed response fields');\n    }\n    return {\n        ok: raw.ok,\n        status: raw.status,\n        body: raw.body,\n        requestUrl: raw.requestUrl,\n        finalUrl: raw.finalUrl,\n    };\n}\nexport async function callNotebooklmRpc(page, rpcId, params, options = {}) {\n    const auth = await getNotebooklmPageAuth(page);\n    const requestBody = buildNotebooklmRpcBody(rpcId, params, auth.csrfToken);\n    const authuser = auth.authuser || '';\n    const url = NOTEBOOKLM_RPC_PATH +\n        `?rpcids=${rpcId}&source-path=${encodeURIComponent(auth.sourcePath)}` +\n        (authuser ? `&authuser=${encodeURIComponent(authuser)}` : '') +\n        `&hl=${encodeURIComponent(options.hl ?? 'en')}` +\n        `&f.sid=${encodeURIComponent(auth.sessionId)}&rt=c`;","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/notebooklm/rpc.js#L196-L232","documentation":"fetchNotebooklmInPage evaluates an in-page fetch against NotebookLM's RPC endpoint and unwraps the evaluated result. Before returning it to callNotebooklmRpc, it validates the shape: ok must be boolean, status an integer, and body/requestUrl/finalUrl strings. If any field is missing or of the wrong type, the in-page bridge did not return a well-formed envelope, so this CommandExecutionError is thrown rather than propagating garbage downstream.","triggerScenarios":"The browser evaluate step in unwrapNotebooklmEvaluateResult returns null/undefined (page navigated mid-call, script injected into a non-NotebookLM frame), the in-page wrapper returns a partial object, or the serialized response loses fields (e.g. status became a string, body undefined).","commonSituations":"The tab navigated away or reloaded while the RPC fetch was in flight; the adapter page is actually a Chrome error page or login interstitial rather than the app; an NotebookLM frontend update changed the in-page hook the wrapper relies on; the CDP evaluate returned a serialized object with dropped fields.","solutions":["Re-run the command after confirming the NotebookLM tab is fully loaded on a notebook/home URL (not a login or error page).","Re-open the session with `opencli notebooklm open <notebook>` so the adapter attaches to a fresh page before retrying.","Check for recent NotebookLM UI changes; update opencli to the latest version that matches the current in-page response shape.","If reproducible, log the raw evaluated value from unwrapNotebooklmEvaluateResult to identify which field is malformed and file an issue."],"exampleFix":"// before: calling RPC on a page that may have navigated\nconst res = await fetchNotebooklmInPage(page, method, body);\n// after: guard the session state first\nconst state = await getNotebooklmPageState(page);\nif (state.kind === null) await openNotebooklmSession(page);\nconst res = await fetchNotebooklmInPage(page, method, body);","handlingStrategy":"type-guard","validationCode":"// before relying on the RPC envelope, verify the page is still on NotebookLM\nconst url = new URL(page.url());\nif (!url.hostname.endsWith('notebooklm.google.com')) await reopenNotebooklmSession(page);","typeGuard":"function isValidRpcEnvelope(raw) {\n  return !!raw && typeof raw === 'object' &&\n    typeof raw.ok === 'boolean' &&\n    Number.isInteger(raw.status) &&\n    typeof raw.body === 'string' &&\n    typeof raw.requestUrl === 'string' &&\n    typeof raw.finalUrl === 'string';\n}","tryCatchPattern":"try {\n  const res = await fetchNotebooklmInPage(page, method, body);\n  // use res\n} catch (e) {\n  if (e instanceof CommandExecutionError && e.message.includes('malformed response fields')) {\n    await reopenNotebooklmSession(page); // recover by re-attaching a fresh page\n  } else throw e;\n}","preventionTips":["Confirm the attached tab is fully loaded on a notebooklm.google.com URL before issuing RPC calls.","Re-open the session after any navigation or long idle period.","Pin a recent opencli version known to match the current NotebookLM frontend.","Validate the envelope shape at call sites instead of assuming fetchNotebooklmInPage always succeeds."],"tags":["rpc","malformed-response","notebooklm","browser-automation"],"backgroundTag":"malformed-response-payload","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}