jackwener/OpenCLI · error · AuthRequiredError
Taobao tracknick cookie absent after navigation
Error message
Taobao tracknick cookie absent after navigation
What it means
verifyTaobaoIdentity navigates to the Taobao my_itaobao page and requires the 'tracknick' cookie to confirm an authenticated session. If page.getCookies() for https://www.taobao.com contains no tracknick cookie, the library throws AuthRequiredError because the session is not (or no longer) logged in. This is a deliberate signal that the caller must re-authenticate.
Source
Thrown at clis/taobao/auth.js:22
async function hasTaobaoSessionCookie(page) {
const cookies = await page.getCookies({ url: 'https://www.taobao.com' });
return cookies.some(c => c.name === 'tracknick' && c.value);
}
async function verifyTaobaoIdentity(page) {
if (!await hasTaobaoSessionCookie(page)) {
throw new AuthRequiredError('taobao.com', 'Taobao tracknick cookie missing — anonymous');
}
await page.goto('https://i.taobao.com/my_itaobao');
await page.wait(2);
const finalUrl = await page.evaluate(`location.href`);
if (/login\.taobao\.com\/member\/login/.test(String(finalUrl || ''))) {
throw new AuthRequiredError('taobao.com', `Taobao my_itaobao redirected to login: ${finalUrl}`);
}
const cookies = await page.getCookies({ url: 'https://www.taobao.com' });
const tracknick = cookies.find(c => c.name === 'tracknick')?.value || '';
if (!tracknick) {
throw new AuthRequiredError('taobao.com', 'Taobao tracknick cookie absent after navigation');
}
const domInfo = await page.evaluate(`
(() => {
const nick = (document.querySelector('.user-nick, .site-nav-user, .user-name')?.innerText || '').trim();
const html = document.body?.innerHTML || '';
const userIdMatch = html.match(/userId[\"'\\s:=]+(\\d+)/i);
return { nickname: nick, user_id: userIdMatch?.[1] || '' };
})()
`);
let decodedTracknick = '';
try {
decodedTracknick = JSON.parse('"' + tracknick.replace(/\\/g, '\\\\') + '"');
} catch {
decodedTracknick = tracknick;
}
const nickname = domInfo.nickname || decodedTracknick;
if (!domInfo.user_id) {
throw new CommandExecutionError('Taobao my_itaobao rendered but no user_id extractable — stale cookie2 or layout drift');View on GitHub (pinned to 49907e53dc)
Solutions
- Run the interactive login flow (loginUrl https://login.taobao.com/member/login.jhtml) and complete it before verifying
- Persist and restore cookies/storage state from a previously successful login so tracknick exists on startup
- Wait and retry the poll: the poll() callback intentionally throws this until hasTaobaoSessionCookie passes, so loop until user logs in
- Check that the browser context is the same one used for login (no incognito/isolated context wipe)
- Manually log into taobao.com in the controlled browser and confirm tracknick exists in devtools cookies
Example fix
// before
await verifyTaobaoIdentity(page); // throws if not logged in
// after
if (!(await hasTaobaoSessionCookie(page))) {
await interactiveLogin(page, 'https://login.taobao.com/member/login.jhtml');
}
await verifyTaobaoIdentity(page); Defensive patterns
Strategy: try-catch
Validate before calling
const cookies = await page.getCookies({ url: 'https://www.taobao.com' });
const hasTracknick = cookies.some(c => c.name === 'tracknick');
if (!hasTracknick) throw new Error('Run taobao login first'); Type guard
function isAuthed(cookies) {
return Array.isArray(cookies) && cookies.some(c => c.name === 'tracknick' && c.value);
} Try / catch
try {
const id = await verifyTaobaoIdentity(page);
} catch (e) {
if (e instanceof AuthRequiredError) {
await runTaobaoLogin(page); // interactive login via login.jhtml
return verifyTaobaoIdentity(page);
}
throw e;
} Prevention
- Persist cookies/storage state after each successful login and restore on startup
- Call hasTaobaoSessionCookie before any authenticated scrape
- Keep the login browser context alive; avoid recreating contexts mid-session
- Watch for login.taobao.com redirects and treat them as re-login signals
When it happens
Trigger: Calling verifyTaobaoIdentity (or the auth poll flow) after page.goto on the my_itaobao URL when getCookies({url:'https://www.taobao.com'}) returns no cookie named 'tracknick'. Also triggered when the login redirect check passed but the session cookie was never set (bot detection, fresh browser context).
Common situations: Expired or cleared Taobao session; running in a fresh browser profile with no prior login; Taobao login blocked by anti-bot verification (slider captcha) so cookies never land; cookie domain scoping so tracknick isn't visible for www.taobao.com.
Related errors
- Taobao tracknick cookie missing — anonymous
- Bilibili ${label} API requires login or permission: ${messag
- bilibili.com
- result.detail (auth required from Claude probe)
- auth
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/c5044ee445207a87.
Report an issue: GitHub.