jackwener/OpenCLI · error · CommandExecutionError

Unexpected Rednote probe: ${JSON.stringify(probe)}

Error message

Unexpected Rednote probe: ${JSON.stringify(probe)}

What it means

verifyRednoteIdentity runs an in-page probe against window.__INITIAL_STATE__ to confirm the Rednote session. The probe classifies every failure it can recognize as kind:'auth' (thrown as AuthRequiredError) or returns ok:true on success. If the probe returns anything else — null/undefined (evaluate failed), an unexpected shape, or a malformed object — the code throws CommandExecutionError with the JSON of the probe so the unrecognized state is visible.

Source

Thrown at clis/rednote/auth.js:35

      const state = window.__INITIAL_STATE__;
      if (!state?.user) {
        return { kind: 'auth', detail: 'Rednote __INITIAL_STATE__.user missing' };
      }
      const loggedIn = state.user.loggedIn?._value;
      const userInfo = state.user.userInfo?._value || {};
      if (loggedIn !== true) {
        return { kind: 'auth', detail: 'Rednote loggedIn._value=' + String(loggedIn) + ' — anonymous' };
      }
      const userId = String(userInfo.userId || userInfo.user_id || '');
      const nickname = String(userInfo.nickname || userInfo.name || '');
      if (!userId) {
        return { kind: 'auth', detail: 'Rednote logged-in but userId missing — stale session' };
      }
      return { ok: true, user_id: userId, nickname };
    })()
  `);
  if (probe?.kind === 'auth') throw new AuthRequiredError('rednote.com', probe.detail);
  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Rednote probe: ${JSON.stringify(probe)}`);
  return { user_id: probe.user_id, nickname: probe.nickname };
}

registerSiteAuthCommands({
  site: 'rednote',
  domain: 'rednote.com',
  loginUrl: 'https://www.rednote.com/explore',
  columns: ['user_id', 'nickname'],
  quickCheck: hasRednoteSessionCookie,
  verify: verifyRednoteIdentity,
  poll: async (page) => {
    if (!await hasRednoteSessionCookie(page)) {
      throw new AuthRequiredError('rednote.com', 'Waiting for Rednote web_session cookie');
    }
    return verifyRednoteIdentity(page);
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the command once — transient page navigation or a mid-evaluate reload commonly produces a null probe.
  2. Log in again via the site's auth flow so the probe sees a fresh, valid __INITIAL_STATE__ (if the state is stale, the probe usually reports kind:'auth' instead, but refresh anyway).
  3. Inspect the JSON in the message: probe:null means evaluate failed (page context gone); an odd object means the state shape changed.
  4. Check for a Rednote frontend update and update this probe script (clis/rednote/auth.js) to match the new __INITIAL_STATE__ shape.
  5. Use a non-headless or less-flagged browser session if anti-bot interstitials are replacing the page before evaluate runs.

Example fix

// before (probe returns null on transient navigation)
if (!probe?.ok) throw new CommandExecutionError(`Unexpected Rednote probe: ${JSON.stringify(probe)}`);
// after (retry once before failing)
if (!probe?.ok) {
  await page.wait(2);
  probe = await page.evaluate(probeScript);
}
if (!probe?.ok) throw new CommandExecutionError(`Unexpected Rednote probe: ${JSON.stringify(probe)}`);
Defensive patterns

Strategy: try-catch

Validate before calling

// before calling, ensure a session cookie exists so the probe path is even reachable
const cookies = await page.getCookies({ url: 'https://www.rednote.com' });
if (!cookies.some(c => c.name === 'web_session' && c.value)) {
  throw new Error('No rednote web_session cookie — run the rednote auth flow first');
}

Type guard

function isProbeOk(p) {
  return typeof p === 'object' && p !== null && p.ok === true
    && typeof p.user_id === 'string' && p.user_id.length > 0;
}

Try / catch

try {
  const identity = await verifyRednoteIdentity(page);
} catch (err) {
  if (err instanceof AuthRequiredError) {
    // re-auth flow
  } else if (err instanceof CommandExecutionError) {
    // transient probe failure: wait and retry once, then surface err.message (contains probe JSON)
    await page.wait(3);
    return retryVerify(page);
  }
  throw err;
}

Prevention

When it happens

Trigger: The page.evaluate call returns null (script error, navigation interrupted mid-evaluate, page clobbered), or returns an object that is neither {kind:'auth'} nor {ok:true} — e.g. Rednote changed its state shape so probe returns {kind:'other'} or truthy garbage, or the browser context was destroyed and evaluate resolved to undefined/null while the web_session cookie still existed.

Common situations: Rednote frontend redeploy changing __INITIAL_STATE__ structure so the IIFE's return paths no longer match; flaky automation runs where the page navigates/reloads between goto and evaluate; anti-bot interstitials replacing the page content; stale automation sessions where evaluate throws internally and the wrapper swallows it, returning null.

Related errors


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