jackwener/OpenCLI · error · AuthRequiredError

creator.xiaohongshu.com

Error message

creator.xiaohongshu.com

What it means

After navigating to the creator note-manager page, the CLI checks location.href; if it points at a /login path, the creator session is not authenticated, so an AuthRequiredError named 'creator.xiaohongshu.com' is thrown to tell the caller (and any CLI wrapper) that interactive browser login is required before this command can run.

Source

Thrown at clis/xiaohongshu/delete-note.js:170

        },
        {
            name: 'execute',
            type: 'boolean',
            default: false,
            help: 'Actually click delete + confirm. Default is dry-run target verification only.',
        },
    ],
    columns: ['status', 'note_id', 'message'],
    func: async (page, kwargs) => {
        try {
            const noteId = normalizeNoteId(kwargs['note-id']);
            const execute = kwargs.execute === true;
            await page.goto(NOTE_MANAGER_URL);
            await page.wait({ time: ROW_SETTLE_MS / 1000 });
            // Detect login redirect (creator.xiaohongshu.com bounces to /login on auth failure)
            const currentUrl = requireEvaluateString(unwrapEvaluateResult(await page.evaluate('() => location.href')), 'current-url');
            if (typeof currentUrl === 'string' && /\/login(?:[/?#]|$)/i.test(new URL(currentUrl).pathname + new URL(currentUrl).search)) {
                throw new AuthRequiredError('creator.xiaohongshu.com');
            }
            // Step 1: ensure 已发布 tab is active (delete only exposed there).
            const tabClicked = requireEvaluateBoolean(unwrapEvaluateResult(await page.evaluate(`
      () => {
        const isVisible = (el) => !!el && el.offsetParent !== null;
        for (const el of document.querySelectorAll('a, button, [role="tab"], div')) {
          const text = (el.innerText || el.textContent || '').trim();
          if (text === '已发布' && isVisible(el)) {
            el.click();
            return true;
          }
        }
        return false;
      }
    `)), 'published-tab');
            if (!tabClicked) {
                throw new CommandExecutionError('xiaohongshu/delete-note: 已发布 tab not found on note-manager; xhs creator UI may have changed.');
            }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Open Chrome with the same profile the CLI uses, visit https://creator.xiaohongshu.com, and complete the login (QR code scan)
  2. Re-run the delete-note command after confirming the note-manager page loads logged-in in that browser
  3. If the CLI supports a login/bootstrap command, run it first to establish the session
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check login state before running the command:
const href = await page.evaluate('() => location.href');
if (/\/login(?:[/?#]|$)/i.test(new URL(href).pathname + new URL(href).search)) {
  throw new Error('Not logged into creator.xiaohongshu.com — log in first');
}

Type guard

function isLoginUrl(href) {
  try {
    const u = new URL(href);
    return /\/login(?:[/?#]|$)/i.test(u.pathname + u.search);
  } catch { return false; }
}

Try / catch

try {
  await cli('xiaohongshu', 'delete-note', { note: noteId });
} catch (err) {
  if (err instanceof AuthRequiredError && err.message === 'creator.xiaohongshu.com') {
    console.error('Open Chrome with the CLI profile, log in at https://creator.xiaohongshu.com (QR scan), then retry.');
  } else throw err;
}

Prevention

When it happens

Trigger: Running delete-note without being logged into creator.xiaohongshu.com in the controlled Chrome profile; the login cookie/session having expired; running on a fresh machine or fresh browser profile with no XHS session; XHS invalidating the session server-side.

Common situations: CI/headless environments where the user never logged in; sessions expiring overnight; cookie cleanup extensions wiping auth cookies; running under a different Chrome profile than the one used to log in.

Related errors


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