DIYgod/RSSHub · error · Error

Could not locate initials script on page

Error message

Could not locate initials script on page

What it means

The xhamster handler loads the creator page and reads the text of the #initials-script element; if it is empty the page did not carry the expected JSON bootstrap blob. This usually means xhamster served a different page (block, age gate, regional redirect, bot challenge) than the one expected.

Source

Thrown at lib/routes/xhamster/index.ts:110

        meta += `${meta ? ' · ' : ''}<strong>Views:</strong> ${views}`;
    }

    return `
        <img src="${thumb}" alt="${video.title}" style="max-width:100%" />
        <p>${meta}</p>
    `.trim();
}

async function handler(ctx) {
    const { creators } = ctx.req.param();
    const pageUrl = `https://xhamster.com/creators/${encodeURIComponent(creators)}/newest`;

    const response = await got(pageUrl);

    const $ = load(response.data);
    const initialsRaw = $('#initials-script').text();
    if (!initialsRaw) {
        throw new Error('Could not locate initials script on page');
    }

    let initials: Initials;
    try {
        initials = extractInitials(initialsRaw);
    } catch {
        throw new Error('Failed to parse page data');
    }

    const creatorName = initials.infoComponent?.pornstarTop?.name ?? creators;
    const videos = initials.trendingVideoSectionComponent?.videoListProps?.videoThumbProps ?? [];

    const items = videos.map((video) => ({
        title: `${video.title}${video.isUHD ? ' [4K]' : ''}`,
        link: video.pageURL,
        pubDate: video.created ? parseDate(video.created * 1000) : undefined,
        author: creatorName,
        description: renderDescription(video),

View on GitHub (pinned to bed535e087)

Solutions

  1. Fetch https://xhamster.com/creators/<slug>/newest from the RSSHub host and confirm the #initials-script tag exists in the raw HTML.
  2. Route RSSHub egress through a region/IP that xhamster serves normally.
  3. If the tag was renamed, update the selector at index.ts:108 and report to the maintainer (eve2ptp).
Defensive patterns

Strategy: validation

Validate before calling

// Confirm the page carries the bootstrap script before parsing
const resp = await got(pageUrl);
const $ = load(resp.data);
if (!$('#initials-script').length || !$('#initials-script').text()) {
    throw new Error('xhamster did not serve the expected page (blocked or template changed)');
}

Type guard

function isXhamsterNoScriptError(e: unknown): boolean {
    return e instanceof Error && /Could not locate initials script on page/i.test(e.message);
}

Try / catch

try {
    return await xhamsterHandler(ctx);
} catch (e) {
    if (isXhamsterNoScriptError(e)) {
        // likely geo/IP block — retry via proxy or return a clear message
        return ctx.json({ error: 'xhamster page unavailable from this host (blocked?)' }, 502);
    }
    throw e;
}

Prevention

When it happens

Trigger: got(pageUrl) returns HTML in which $('#initials-script').text() is empty — index.ts:108-110. Happens when the route is geo/IP blocked, Cloudflare/challenge interposes, or xhamster renamed the script tag.

Common situations: Running RSSHub from a region/IP xhamster blocks; xhamster deployed a new front-end that no longer emits #initials-script; response was an error/age-gate page.

Related errors


AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12). Data as JSON: /api/errors/ca05a7d08842bd78. Report an issue: GitHub.