jackwener/OpenCLI · error · ArgumentError

xiaohongshu/follow: profile URL must be an exact https://*.x

Error message

xiaohongshu/follow: profile URL must be an exact https://*.xiaohongshu.com URL

What it means

assertUserId enforces that a URL-form argument is an exact https URL on a xiaohongshu.com host (or subdomain). http:// URLs, other hosts (e.g. xhslink.com short links or mirror domains), are rejected with ArgumentError to prevent following on the wrong domain or an insecure scheme.

Source

Thrown at clis/xiaohongshu/follow.js:50

function requireActionResult(payload, context) {
    const inner = unwrapEvaluateResult(payload);
    if (!inner || typeof inner !== 'object' || Array.isArray(inner) || typeof inner.ok !== 'boolean') {
        throw new CommandExecutionError(`xiaohongshu/follow: malformed ${context} payload`);
    }
    return inner;
}

function assertUserId(raw) {
    const input = String(raw ?? '').trim();
    if (/^https?:\/\//i.test(input)) {
        let parsed;
        try {
            parsed = new URL(input);
        } catch {
            throw new ArgumentError('xiaohongshu/follow: invalid profile URL');
        }
        if (parsed.protocol !== 'https:' || !isXiaohongshuHost(parsed.hostname)) {
            throw new ArgumentError('xiaohongshu/follow: profile URL must be an exact https://*.xiaohongshu.com URL');
        }
        const match = parsed.pathname.match(/^\/user\/profile\/([a-zA-Z0-9]{8,32})\/?$/);
        if (!match) {
            throw new ArgumentError('xiaohongshu/follow: profile URL must be /user/profile/<userId>');
        }
        return match[1];
    }
    const userId = normalizeXhsUserId(raw);
    if (!userId || !USER_ID_RE.test(userId)) {
        throw new ArgumentError(
            'xiaohongshu/follow: user-id must be a Xiaohongshu user ID (e.g. 5d8f88dc0000000001005d3a) or full profile URL',
        );
    }
    return userId;
}

/**
 * The injected page script. Lives in the browser context, so it can't import

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use the canonical https URL on a xiaohongshu.com domain: https://www.xiaohongshu.com/user/profile/<userId>.
  2. Resolve short links (xhslink.com) in a browser first, then copy the final xiaohongshu.com URL.
  3. Or skip the URL entirely and pass the raw user ID extracted from the profile page.

Example fix

// before
opencli xiaohongshu follow --user-id 'http://www.xiaohongshu.com/user/profile/5d8f88dc0000000001005d3a'
// after
opencli xiaohongshu follow --user-id 'https://www.xiaohongshu.com/user/profile/5d8f88dc0000000001005d3a'
Defensive patterns

Strategy: validation

Validate before calling

function isCanonicalXhsProfileUrl(raw) {
  try {
    const u = new URL(String(raw));
    return u.protocol === 'https:' &&
      (u.hostname === 'xiaohongshu.com' || u.hostname.endsWith('.xiaohongshu.com'));
  } catch { return false; }
}

Try / catch

try {
  await opencliFollow(url);
} catch (err) {
  if (err.code === 'ARGUMENT' && err.message.includes('https://*.xiaohongshu.com')) {
    // resolve short links / fix scheme, then retry
  }
  throw err;
}

Prevention

When it happens

Trigger: Passing http:// instead of https://, or a profile URL on a non-Xiaohongshu domain (short link xhslink.com, a redirector, or a phishy mirror) to the follow command's --user-id option.

Common situations: Sharing links copied from third-party aggregators; using the share-sheet short link instead of the canonical www.xiaohongshu.com URL; older http bookmarks; enterprise proxies rewriting schemes.

Related errors


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