{"record":{"id":"a9094057d9f79999","repo":"jackwener/OpenCLI","slug":"rednote-notifications-unexpected-evaluate-respons","errorCode":null,"errorMessage":"rednote notifications: unexpected evaluate response","messagePattern":"rednote notifications: unexpected evaluate response","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/rednote/notifications.js","lineNumber":130,"sourceCode":"    navigateBefore: false,\n    args: [\n        {\n            name: 'type',\n            default: 'mentions',\n            help: 'Notification type: mentions, likes, or connections',\n        },\n        { name: 'limit', type: 'int', default: 20, help: 'Number of notifications to return' },\n    ],\n    columns: ['rank', 'user', 'action', 'content', 'note', 'time'],\n    func: async (page, kwargs) => {\n        const type = parseNotificationType(kwargs.type);\n        const limit = parseLimit(kwargs.limit);\n        await page.goto('https://www.rednote.com/notification');\n        await page.wait({ time: 2 });\n        const script = READ_NOTIFICATIONS_JS.replace(JSON.stringify('PLACEHOLDER_TYPE'), JSON.stringify(type));\n        const data = await page.evaluate(script);\n        if (!data || typeof data !== 'object') {\n            throw new CommandExecutionError('rednote notifications: unexpected evaluate response');\n        }\n        if (data.error) {\n            throw new CommandExecutionError(`rednote notifications: ${data.error}${data.detail ? ' (' + data.detail + ')' : ''}`, 'The rednote SPA may still be hydrating; reload www.rednote.com/notification and retry.');\n        }\n        return (data.items || [])\n            .slice(0, limit)\n            .map((row, i) => ({ rank: i + 1, ...row }));\n    },\n});\n","sourceCodeStart":112,"sourceCodeEnd":140,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/rednote/notifications.js#L112-L140","documentation":"After loading the rednote notifications page, the command evaluates an in-page script and expects an object back. If page.evaluate returns null, undefined, or a primitive, it throws CommandExecutionError because the extraction script's contract was violated. This usually indicates the script failed to run or the page context was replaced.","triggerScenarios":"page.evaluate(script) resolving to a non-object: the injected READ_NOTIFICATIONS_JS threw and returned undefined, the SPA navigated/clobbered the document mid-evaluation, or the browser driver returned a serialized non-object value.","commonSituations":"Page redirecting to login or an interstitial between goto and evaluate, slow network leaving the SPA in a broken state, driver/version returning values in an unexpected wrapper, or anti-bot script aborting injected code.","solutions":["Retry the command after reloading https://www.rednote.com/notification","Catch this error and fall back to a full page reload with a longer wait before evaluate","Inspect whether the page is behind a login/interstitial and authenticate first","Check driver versions for evaluate() result-serialization changes"],"exampleFix":"// before\nconst data = await page.evaluate(script);\n// after\nlet data;\ntry { data = await page.evaluate(script); } catch (e) { data = null; }\nif (!data || typeof data !== 'object') {\n  await page.reload(); await page.wait({ time: 3 });\n  data = await page.evaluate(script);\n}","handlingStrategy":"try-catch","validationCode":"const data = await page.evaluate(script); const ok = data !== null && typeof data === 'object' && !Array.isArray(data);","typeGuard":"const isEvaluateObject = (v) => v !== null && typeof v === 'object';","tryCatchPattern":"try { return await fetchNotifications(page, type, limit); } catch (e) { if (e instanceof CommandExecutionError && /unexpected evaluate response/.test(e.message)) { await page.reload(); await page.wait({ time: 3 }); return fetchNotifications(page, type, limit); } throw e; }","preventionTips":["Reload and re-wait before retrying evaluate on SPA pages","Verify the page is not redirecting (login/interstitial) before extraction","Pin and test against your browser driver's evaluate serialization behavior"],"tags":["browser-automation","evaluate","spa"],"backgroundTag":"unexpected-evaluate-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}