jackwener/OpenCLI · error · CommandExecutionError

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

Error message

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

What it means

If the evaluated probe neither reports an auth problem nor returns { ok: true }, verifyYoutubeIdentity throws 'Unexpected YouTube probe: <json>'. This is a contract check: YouTube's page returned a shape the library doesn't recognize, so it surfaces the raw probe for debugging.

Source

Thrown at clis/youtube/auth.js:37

      // ytcfg LOGGED_IN is the reliable signed-in signal; the avatar button is a fallback.
      const loggedIn = !!(cfg && cfg.get('LOGGED_IN') === true) || !!document.querySelector('#avatar-btn');
      if (!loggedIn) {
        return { kind: 'auth', detail: 'YouTube ytcfg LOGGED_IN not true and no avatar — not signed in' };
      }
      // Name is best-effort: YouTube's masthead avatar exposes a generic
      // "Account menu" aria-label, so the channel name is often unavailable
      // without opening the menu. Surface it when present, else leave empty.
      let name = '';
      try { const ctx = cfg && cfg.get('INNERTUBE_CONTEXT'); name = (ctx && ctx.user && ctx.user.identityName) || ''; } catch {}
      if (!name) {
        const aria = (document.querySelector('#avatar-btn')?.getAttribute('aria-label') || '').trim();
        if (aria && !/^account menu$/i.test(aria)) name = aria;
      }
      return { ok: true, name: String(name || '') };
    })()
  `);
  if (probe?.kind === 'auth') throw new AuthRequiredError('www.youtube.com', probe.detail);
  if (!probe?.ok) throw new CommandExecutionError(`Unexpected YouTube probe: ${JSON.stringify(probe)}`);
  return { name: probe.name };
}

registerSiteAuthCommands({
  site: 'youtube',
  domain: 'www.youtube.com',
  loginUrl: 'https://accounts.google.com/ServiceLogin?service=youtube&continue=https%3A%2F%2Fwww.youtube.com%2F',
  columns: ['name'],
  quickCheck: hasGoogleSessionCookie,
  verify: verifyYoutubeIdentity,
  poll: async (page) => {
    if (!await hasGoogleSessionCookie(page)) {
      throw new AuthRequiredError('www.youtube.com', 'Waiting for Google session cookies');
    }
    return verifyYoutubeIdentity(page);
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Inspect the JSON in the message to see the actual probe value
  2. Update the probe script to match the current YouTube DOM/ytcfg API
  3. Ensure page.evaluate returns a JSON-serializable object and the page fully loaded first
  4. Retry after re-logging in if the page was in an abnormal state

Example fix

// before
if (!probe?.ok) throw new CommandExecutionError(`Unexpected YouTube probe: ${JSON.stringify(probe)}`);
// after
if (!probe) { await page.wait(3); probe = await page.evaluate(probeJs); }
if (!probe?.ok) throw new CommandExecutionError(`Unexpected YouTube probe: ${JSON.stringify(probe)}`);
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure the page is in a normal signed-in state before probing
await page.goto('https://www.youtube.com/');
await page.wait(3);
if (page.url().includes('ServiceLogin')) throw new Error('Redirected to login; session invalid');

Type guard

function isKnownProbe(p) {
  return p !== null && typeof p === 'object' && (('ok' in p) || p.kind === 'auth');
}

Try / catch

try {
  await cli.youtube.whoami();
} catch (e) {
  const m = /Unexpected YouTube probe: (.+)/.exec(e.message);
  if (m) {
    console.error('Probe payload for debugging:', m[1]);
    // inspect payload, update/retry
  } else throw e;
}

Prevention

When it happens

Trigger: probe is null/undefined (evaluate failed to return), the IIFE threw silently or returned an unexpected object, or YouTube's page markup changed so the avatar/ytcfg probes produce a novel shape.

Common situations: YouTube frontend rollout changing ytcfg or #avatar-btn; evaluate returning undefined due to serialization; probe script truncated; page in an error state (e.g. captcha page).

Related errors


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