{"record":{"id":"481a61ec22a1d0e5","repo":"jackwener/OpenCLI","slug":"browser-session-required-for-bilibili-comments","errorCode":null,"errorMessage":"Browser session required for bilibili comments","messagePattern":"Browser session required for bilibili comments","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/comments.js","lineNumber":118,"sourceCode":"}\n\ncli({\n    site: 'bilibili',\n    name: 'comments',\n    access: 'read',\n    description: '获取 B站视频评论（官方 API；用 --parent <rpid> 读取某条评论下的「楼中楼」回复；用 --top 只看置顶评论）',\n    domain: 'www.bilibili.com',\n    strategy: Strategy.COOKIE,\n    args: [\n        { name: 'bvid', required: true, positional: true, help: 'Video BV ID (e.g. BV1WtAGzYEBm)' },\n        { name: 'parent', type: 'int', help: 'rpid of a comment — fetch the replies under it instead of top-level comments' },\n        { name: 'top', type: 'boolean', default: false, help: '只返回置顶评论（与 --parent 互斥）' },\n        { name: 'limit', type: 'int', default: 20, help: 'Number of comments (max 50)' },\n    ],\n    columns: ['rank', 'rpid', 'author', 'text', 'likes', 'replies', 'time'],\n    func: async (page, kwargs) => {\n        if (!page) {\n            throw new CommandExecutionError('Browser session required for bilibili comments');\n        }\n        const limit = parseLimit(kwargs.limit);\n        const parent = parseParent(kwargs.parent);\n        const top = kwargs.top === true;\n        if (top && parent != null) {\n            throw new ArgumentError('bilibili comments --top cannot be combined with --parent (pinned comments only exist at the top level)');\n        }\n        let bvid;\n        try {\n            bvid = await resolveBvid(kwargs.bvid);\n        }\n        catch (error) {\n            throw new ArgumentError(`Cannot resolve Bilibili BV ID from input: ${String(kwargs.bvid ?? '')}`, error instanceof Error ? error.message : String(error));\n        }\n        // Resolve bvid → aid (required by reply API)\n        const view = await apiGet(page, '/x/web-interface/view', { params: { bvid } });\n        const viewData = requireOkPayload(view, 'view');\n        const aid = viewData?.aid;","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/comments.js#L100-L136","documentation":"The bilibili comments command runs inside a cookie-backed browser session (Strategy.COOKIE) because the reply APIs require browser context (cookies/WBI signing). This CommandExecutionError is thrown at the top of the command's func when page is falsy — no browser session was provided or initialized.","triggerScenarios":"Invoking the command programmatically or in an environment where no browser page is passed (headless runner without a session, disabled browser integration, or calling the registered func directly with null page).","commonSituations":"CI environments without the browser/cookie layer; calling func(page, kwargs) directly in tests; browser session failed to launch before dispatch.","solutions":["Run the command through the normal CLI entry point so a browser session is created","Ensure the browser/cookie strategy is enabled and bilibili.com cookies are configured","If embedding, pass a valid page handle to func instead of null/undefined","Check browser launch logs for earlier failures that left page unset"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (!page) {\n    throw new Error('bilibili comments requires a browser session; initialize the CLI session first');\n}","typeGuard":"function hasBrowserSession(page) {\n    return !!page && typeof page.goto === 'function';\n}","tryCatchPattern":"try {\n    const rows = await bilibiliComments(bvid);\n} catch (err) {\n    if (/Browser session required/.test(err.message)) {\n        // initialize the browser/cookie session and retry once\n    } else throw err;\n}","preventionTips":["Always invoke via the CLI entry point so the session is created","Ensure bilibili.com cookies are configured for the COOKIE strategy","Verify browser launch succeeds in CI before running site commands","When embedding, pass a live page handle, not null"],"tags":["browser-session","bilibili","setup"],"backgroundTag":"missing-browser-session","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}