jackwener/OpenCLI · error · CommandExecutionError

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

Error message

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

What it means

CommandExecutionError thrown when the in-page probe result is neither {kind:'auth'} nor {ok:true} — including null/undefined — i.e. an unrecognized shape. It guards against silently returning garbage identity data when page.evaluate fails or the page script returns something unexpected.

Source

Thrown at clis/toutiao/auth.js:53

          for (const v of Object.values(node)) if (v && typeof v === 'object') stack.push(v);
        }
      } catch {}
      if (!userId) {
        const ssoUid = (document.cookie.split('; ').find(c => c.startsWith('sso_uid=')) || '').split('=')[1] || '';
        if (ssoUid) userId = ssoUid;
      }
      if (!nickname) {
        const el = document.querySelector('.user-name, .header-username, .avatar-name, [class*="userName"]');
        nickname = (el?.innerText || '').trim();
      }
      if (!userId) {
        return { kind: 'auth', detail: 'Toutiao dashboard rendered but no user_id surface — stale session' };
      }
      return { ok: true, user_id: userId, nickname };
    })()
  `);
  if (probe?.kind === 'auth') throw new AuthRequiredError('toutiao.com', probe.detail);
  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Toutiao probe: ${JSON.stringify(probe)}`);
  return { user_id: probe.user_id, nickname: probe.nickname };
}

registerSiteAuthCommands({
  site: 'toutiao',
  domain: 'toutiao.com',
  loginUrl: 'https://mp.toutiao.com/auth/page/login',
  columns: ['user_id', 'nickname'],
  quickCheck: hasToutiaoSessionCookie,
  verify: verifyToutiaoIdentity,
  poll: async (page) => {
    if (!await hasToutiaoSessionCookie(page)) {
      throw new AuthRequiredError('toutiao.com', 'Waiting for Toutiao sessionid cookie');
    }
    return verifyToutiaoIdentity(page);
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the command — transient page-load/navigation races are the most common cause of a null probe.
  2. Inspect the JSON embedded in the error message; it shows exactly what the probe returned.
  3. Verify your driver supports evaluate of stringified IIFEs (check Playwright/Puppeteer version) and that nothing blocks inline scripts on mp.toutiao.com.
  4. Ensure the page finished loading at mp.toutiao.com before verify runs (the flow waits only 2s; slow environments need more).
  5. If the failure persists after a site change, update the probe's return contract in clis/toutiao/auth.js.

Example fix

// before
if (!probe?.ok) throw new CommandExecutionError(`Unexpected Toutiao probe: ${JSON.stringify(probe)}`);
// after: retry once before failing
if (!probe?.ok) {
  await page.wait(3);
  probe = await page.evaluate(PROBE_SNIPPET);
  if (!probe?.ok && probe?.kind !== 'auth') {
    throw new CommandExecutionError(`Unexpected Toutiao probe: ${JSON.stringify(probe)}`);
  }
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!page.url().includes('mp.toutiao.com')) {
  await page.goto('https://mp.toutiao.com/');
}
if (typeof page.evaluate !== 'function') {
  throw new Error('Browser driver does not support page.evaluate — required for the toutiao probe');
}

Type guard

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

Try / catch

try {
  const identity = await toutiaoAuthVerify(page);
} catch (err) {
  if (err.name === 'CommandExecutionError' && err.message.startsWith('Unexpected Toutiao probe')) {
    await new Promise(r => setTimeout(r, 3000));
    return toutiaoAuthVerify(page); // single retry for transient navigation races
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling toutiao auth verify when page.evaluate returns null/undefined (script blocked by CSP, navigation mid-evaluation, driver quirk) or a malformed object whose kind is not 'auth' and ok is not true.

Common situations: Browser automation driver version mismatch where string-script evaluate returns undefined; mp.toutiao.com crashing or being replaced by an error/anti-bot page during evaluation; extensions or CSP stripping injected scripts; network drop leaving the page on about:blank.

Related errors


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