DIYgod/RSSHub · error · Error
Unable to fetch visitor cookies. Please set WEIBO_COOKIES. R
Error message
Unable to fetch visitor cookies. Please set WEIBO_COOKIES. Redirection: ${times}, last URL: ${page.url()} What it means
The Playwright-based visitor cookie bootstrap failed. The code expects exactly 2 redirections through m.weibo.cn (initial → visitor.passport.weibo.cn → authed) and a non-empty cookie jar; if times < 2 or no cookies were captured, acquisition is deemed broken and the user is told to supply WEIBO_COOKIES.
Source
Thrown at lib/routes/weibo/utils.ts:109
await page.route('**/*', (route) => {
const request = route.request();
// 1st: initial request, 302 to visitor.passport.weibo.cn; 2nd: auth ok
if (!expectResourceTypes.has(request.resourceType()) || times >= 2) {
route.abort();
return;
}
if (request.url().startsWith(url)) {
times++;
}
route.continue();
});
},
gotoConfig: { waitUntil: 'networkidle' },
});
const cookies: string = await getCookies(page, 'weibo.cn');
await destroy();
if (times < 2 || !cookies) {
throw new Error(`Unable to fetch visitor cookies. Please set WEIBO_COOKIES. Redirection: ${times}, last URL: ${page.url()}`);
}
return cookies;
})();
try {
return await visitorCookiesPromise;
} finally {
visitorCookiesPromise = undefined;
}
});
};
})(),
tryWithCookies: (() => {
let errors = 0;
const verifier = (resp: any): void => {
if (resp?.data?.ok === -100) {
throw new RenewWeiboCookiesError(`Cookies expired. Msg: ${resp?.data?.msg || ''} ${resp?.data?.url || ''}`);
}View on GitHub (pinned to bed535e087)
Solutions
- Install the browser runtime: run `npx playwright install chromium` (and OS deps via `playwright install-deps`) on the RSSHub host.
- Set WEIBO_COOKIES manually to skip the Playwright visitor path.
- Check RSSHub can reach m.weibo.cn from its network egress (no proxy/captcha intercepting) and that request abortion logic at utils.ts:94-97 still matches weibo's resource types.
Defensive patterns
Strategy: fallback
Validate before calling
// Pre-flight: confirm Playwright + chromium are usable before relying on visitor cookies
import { chromium } from 'playwright';
let browser;
try {
browser = await chromium.launch();
} catch (e) {
throw new Error('Playwright chromium unavailable — visitor cookie fetch will fail. Set WEIBO_COOKIES or install chromium.');
} finally {
await browser?.close();
} Type guard
function isWeiboVisitorFetchError(e: unknown): boolean {
return e instanceof Error && /Unable to fetch visitor cookies/i.test(e.message);
} Try / catch
try {
return await weiboUtils.tryWithCookies(cb);
} catch (e) {
if (isWeiboVisitorFetchError(e) && process.env.WEIBO_COOKIES) {
// last resort: retry once with the operator-supplied cookies
return await cb(process.env.WEIBO_COOKIES, () => {});
}
throw e;
} Prevention
- Install chromium and OS deps in the RSSHub image (`playwright install --with-deps chromium`).
- Keep WEIBO_COOKIES configured as a fallback even when auto mode is primary.
- Monitor redirect count `times` in logs — values < 2 indicate the visitor flow is drifting.
When it happens
Trigger: getPlaywrightPage loads m.weibo.cn but the redirect counter `times` stays below 2 (blocked/aborted early, network error, or flow changed) or getCookies(page,'weibo.cn') returns empty — utils.ts:108-109.
Common situations: Playwright/Chromium not installed or missing system deps on the host; m.weibo.cn changed its visitor-login redirect chain; the host IP is geo/IP-blocked by weibo; container lacks the browser runtime.
Related errors
- No response received from ${apiUrl}
- Bilibili browser mode did not receive a video list response
- Bilibili browser mode returned unexpected video list API sta
- Bilibili browser mode returned non-JSON response with status
- Got error code ${data.code} while fetching in browser mode:
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/8c2c0204440a899d.
Report an issue: GitHub.