jackwener/OpenCLI · error · ArgumentError

URL must be on tiktok.com (got ${parsed.hostname})

Error message

URL must be on tiktok.com (got ${parsed.hostname})

What it means

After successful URL parsing, parseTikTokVideoUrl verifies the hostname matches /(^|\.)tiktok\.com$/i. Any other host (or an exact-looking decoy domain) is rejected with the offending hostname in the message.

Source

Thrown at clis/tiktok/utils.js:122

export function parseTikTokVideoUrl(value) {
    const raw = String(value ?? '').trim();
    if (!raw) {
        throw new ArgumentError(
            'video URL is required',
            'Example: opencli tiktok comment https://www.tiktok.com/@user/video/1234567890 "..."',
        );
    }
    let parsed;
    try {
        parsed = new URL(raw);
    } catch {
        throw new ArgumentError(
            `invalid video URL: ${raw}`,
            'Example: https://www.tiktok.com/@user/video/1234567890',
        );
    }
    if (!/(^|\.)tiktok\.com$/i.test(parsed.hostname)) {
        throw new ArgumentError(
            `URL must be on tiktok.com (got ${parsed.hostname})`,
            'Example: https://www.tiktok.com/@user/video/1234567890',
        );
    }
    const match = parsed.pathname.match(/^\/@([A-Za-z0-9._-]+)\/video\/(\d+)\/?$/);
    if (!match) {
        throw new ArgumentError(
            'URL must follow /@<username>/video/<id> format',
            'Example: https://www.tiktok.com/@user/video/1234567890',
        );
    }
    return {
        url: parsed.toString(),
        username: match[1],
        videoId: match[2],
    };
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use a URL on tiktok.com or a *.tiktok.com subdomain
  2. Resolve shorteners to their final tiktok.com destination before calling
  3. Check the pasted domain for typos (tikok.com, tiktok.org, etc.)

Example fix

// before
parseTikTokVideoUrl('https://example.com/video/123')
// after
parseTikTokVideoUrl('https://www.tiktok.com/@user/video/123')
Defensive patterns

Strategy: validation

Validate before calling

const h = new URL(value).hostname; if (!/(^|\.)tiktok\.com$/i.test(h)) throw new Error(`not a tiktok.com URL: ${h}`);

Type guard

const isTikTokUrl = (v) => { try { return /(^|\.)tiktok\.com$/i.test(new URL(String(v)).hostname); } catch { return false; } };

Try / catch

try { parseTikTokVideoUrl(url); } catch (e) { if (/URL must be on tiktok\.com/.test(e.message)) console.error('Only tiktok.com hosts are supported'); else throw e; }

Prevention

When it happens

Trigger: Passing a valid URL whose hostname is not tiktok.com or a subdomain of it — e.g. youtube.com links, typos like tiktok.com.evil.io (rejected by the anchored regex), or tiktokcom without the dot.

Common situations: Extracting a link from a playlist of mixed-platform URLs; typo'd domains; redirector/shortener hosts; pasting a Douyin URL.

Related errors


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