{"record":{"id":"8c2c0204440a899d","repo":"DIYgod/RSSHub","slug":"unable-to-fetch-visitor-cookies-please-set-weibo","errorCode":null,"errorMessage":"Unable to fetch visitor cookies. Please set WEIBO_COOKIES. Redirection: ${times}, last URL: ${page.url()}","messagePattern":"Unable to fetch visitor cookies\\. Please set WEIBO_COOKIES\\. Redirection: (.+?), last URL: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/routes/weibo/utils.ts","lineNumber":109,"sourceCode":"                            await page.route('**/*', (route) => {\n                                const request = route.request();\n                                // 1st: initial request, 302 to visitor.passport.weibo.cn; 2nd: auth ok\n                                if (!expectResourceTypes.has(request.resourceType()) || times >= 2) {\n                                    route.abort();\n                                    return;\n                                }\n                                if (request.url().startsWith(url)) {\n                                    times++;\n                                }\n                                route.continue();\n                            });\n                        },\n                        gotoConfig: { waitUntil: 'networkidle' },\n                    });\n                    const cookies: string = await getCookies(page, 'weibo.cn');\n                    await destroy();\n                    if (times < 2 || !cookies) {\n                        throw new Error(`Unable to fetch visitor cookies. Please set WEIBO_COOKIES. Redirection: ${times}, last URL: ${page.url()}`);\n                    }\n                    return cookies;\n                })();\n\n                try {\n                    return await visitorCookiesPromise;\n                } finally {\n                    visitorCookiesPromise = undefined;\n                }\n            });\n        };\n    })(),\n    tryWithCookies: (() => {\n        let errors = 0;\n        const verifier = (resp: any): void => {\n            if (resp?.data?.ok === -100) {\n                throw new RenewWeiboCookiesError(`Cookies expired. Msg: ${resp?.data?.msg || ''} ${resp?.data?.url || ''}`);\n            }","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/weibo/utils.ts#L91-L127","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Pre-flight: confirm Playwright + chromium are usable before relying on visitor cookies\nimport { chromium } from 'playwright';\nlet browser;\ntry {\n    browser = await chromium.launch();\n} catch (e) {\n    throw new Error('Playwright chromium unavailable — visitor cookie fetch will fail. Set WEIBO_COOKIES or install chromium.');\n} finally {\n    await browser?.close();\n}","typeGuard":"function isWeiboVisitorFetchError(e: unknown): boolean {\n    return e instanceof Error && /Unable to fetch visitor cookies/i.test(e.message);\n}","tryCatchPattern":"try {\n    return await weiboUtils.tryWithCookies(cb);\n} catch (e) {\n    if (isWeiboVisitorFetchError(e) && process.env.WEIBO_COOKIES) {\n        // last resort: retry once with the operator-supplied cookies\n        return await cb(process.env.WEIBO_COOKIES, () => {});\n    }\n    throw e;\n}","preventionTips":["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."],"tags":["weibo","cookies","playwright","browser","network"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}