jackwener/OpenCLI · error · AuthRequiredError
www.youtube.com
Error message
www.youtube.com
What it means
verifyYoutubeIdentity first checks for Google session cookies (SID, SAPISID, or __Secure-1PSID). If none are present it throws AuthRequiredError with domain 'www.youtube.com', signaling the caller must log in before YouTube identity can be verified.
Source
Thrown at clis/youtube/auth.js:12
import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { registerSiteAuthCommands } from '../_shared/site-auth.js';
async function hasGoogleSessionCookie(page) {
const cookies = await page.getCookies({ url: 'https://www.youtube.com' });
const names = new Set(cookies.map(c => c.name));
return names.has('SID') || names.has('SAPISID') || names.has('__Secure-1PSID');
}
async function verifyYoutubeIdentity(page) {
if (!await hasGoogleSessionCookie(page)) {
throw new AuthRequiredError('www.youtube.com', 'Google session cookies missing');
}
await page.goto('https://www.youtube.com/');
await page.wait(3);
const probe = await page.evaluate(`
(() => {
const cfg = (typeof window !== 'undefined' && window.ytcfg && typeof window.ytcfg.get === 'function') ? window.ytcfg : null;
// 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();View on GitHub (pinned to 49907e53dc)
Solutions
- Run the library's login flow for the 'youtube' site (loginUrl: accounts.google.com ServiceLogin) to establish Google session cookies
- Point the tool at the browser profile that is already logged into Google
- Re-login if the session expired (cookies are stale)
- Verify cookies are being loaded from the correct storage path
Defensive patterns
Strategy: try-catch
Validate before calling
// before calling youtube commands
const cookies = await getCookies('https://www.youtube.com');
const names = new Set(cookies.map(c => c.name));
if (!['SID','SAPISID','__Secure-1PSID'].some(n => names.has(n))) {
await runLoginFlow('youtube');
} Type guard
function hasGoogleSession(cookies) {
const names = new Set(cookies.map(c => c.name));
return names.has('SID') || names.has('SAPISID') || names.has('__Secure-1PSID');
} Try / catch
try {
const identity = await cli.youtube.whoami();
} catch (e) {
if (e.name === 'AuthRequiredError' && e.message.includes('www.youtube.com')) {
await cli.login('youtube');
return cli.youtube.whoami();
}
throw e;
} Prevention
- Run the login flow before YouTube commands in fresh profiles
- Use a persistent browser profile so cookies survive restarts
- Detect AuthRequiredError and trigger login automatically
- Re-login when cookie age is high
When it happens
Trigger: Calling a YouTube command with a browser profile that has never logged into Google, cookies expired/cleared, or a fresh/incognito automation profile.
Common situations: CI runners with empty cookie jars; users who cleared cookies; cookie store location changed after browser update; using a profile different from the one used to log in.
Related errors
- auth
- www.youtube.com
- www.youtube.com
- Not logged in (SAPISID cookie missing)
- Not logged in (SAPISID cookie missing)
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/f815cb226de15008.
Report an issue: GitHub.