jackwener/OpenCLI · error · CommandExecutionError

rednote notifications: unexpected evaluate response

Error message

rednote notifications: unexpected evaluate response

What it means

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.

Source

Thrown at clis/rednote/notifications.js:130

    navigateBefore: false,
    args: [
        {
            name: 'type',
            default: 'mentions',
            help: 'Notification type: mentions, likes, or connections',
        },
        { name: 'limit', type: 'int', default: 20, help: 'Number of notifications to return' },
    ],
    columns: ['rank', 'user', 'action', 'content', 'note', 'time'],
    func: async (page, kwargs) => {
        const type = parseNotificationType(kwargs.type);
        const limit = parseLimit(kwargs.limit);
        await page.goto('https://www.rednote.com/notification');
        await page.wait({ time: 2 });
        const script = READ_NOTIFICATIONS_JS.replace(JSON.stringify('PLACEHOLDER_TYPE'), JSON.stringify(type));
        const data = await page.evaluate(script);
        if (!data || typeof data !== 'object') {
            throw new CommandExecutionError('rednote notifications: unexpected evaluate response');
        }
        if (data.error) {
            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.');
        }
        return (data.items || [])
            .slice(0, limit)
            .map((row, i) => ({ rank: i + 1, ...row }));
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the command after reloading https://www.rednote.com/notification
  2. Catch this error and fall back to a full page reload with a longer wait before evaluate
  3. Inspect whether the page is behind a login/interstitial and authenticate first
  4. Check driver versions for evaluate() result-serialization changes

Example fix

// before
const data = await page.evaluate(script);
// after
let data;
try { data = await page.evaluate(script); } catch (e) { data = null; }
if (!data || typeof data !== 'object') {
  await page.reload(); await page.wait({ time: 3 });
  data = await page.evaluate(script);
}
Defensive patterns

Strategy: try-catch

Validate before calling

const data = await page.evaluate(script); const ok = data !== null && typeof data === 'object' && !Array.isArray(data);

Type guard

const isEvaluateObject = (v) => v !== null && typeof v === 'object';

Try / catch

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; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/a9094057d9f79999. Report an issue: GitHub.