{"record":{"id":"3f7a6b9434fc1d11","repo":"jackwener/OpenCLI","slug":"browser-session-required-for-bilibili-video","errorCode":null,"errorMessage":"Browser session required for bilibili video","messagePattern":"Browser session required for bilibili video","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/video.js","lineNumber":45,"sourceCode":"  if (value == null) return '';\n  if (typeof value === 'string') return value;\n  throw new CommandExecutionError(`${label} returned a malformed string`);\n}\n\ncli({\n  site: 'bilibili',\n  name: 'video',\n    access: 'read',\n  description: 'Get Bilibili video metadata (title, author, duration, stats, etc.)',\n  strategy: Strategy.COOKIE,\n  args: [\n    { name: 'bvid', required: true, positional: true, help: 'BV ID, video URL, or b23.tv short link' },\n    { name: 'page', required: false, help: '分P 选集序号（从 1 开始）。多 P 视频指定某一集，title/cid 返回该集；缺省取整集默认（P1）' },\n  ],\n  columns: ['field', 'value'],\n  func: async (page, kwargs) => {\n    if (!page) {\n      throw new CommandExecutionError('Browser session required for bilibili video');\n    }\n\n    // 选集序号（--page）：缺省 null = 不下钻分P，保持整集（P1）旧行为。\n    const selectedPage = parsePageArg(kwargs.page);\n\n    // Resolve BV ID from three advertised input forms:\n    //   1. Bare \"BV...\" id\n    //   2. Full bilibili.com/video/<BV>... URL (with or without query string / www / m.)\n    //   3. b23.tv short link (delegated to resolveBvid)\n    // resolveBvid() alone handles (1) and (3) but not (2), so we pre-extract\n    // from bilibili URLs before falling through.\n    const input = String(kwargs.bvid ?? '').trim();\n    const bilibiliUrlMatch = input.match(/bilibili\\.com\\/(?:video|bangumi\\/play)\\/(BV[A-Za-z0-9]+)/i);\n    const bvid = bilibiliUrlMatch ? bilibiliUrlMatch[1] : await resolveBvid(input);\n\n    // Navigate to video page first so subsequent api call shares a primed session.\n    await page.goto(`https://www.bilibili.com/video/${bvid}/`);\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/video.js#L27-L63","documentation":"The bilibili video command requires a live browser session (page) to call Bilibili's web APIs. If the func callback receives no page object, it throws this CommandExecutionError immediately, because authenticated/browser-context requests cannot proceed.","triggerScenarios":"Running the video command without an active browser session — e.g. no session started via the CLI's browser/login flow, a stale/expired session, or invoking the command in an environment where the browser bridge is unavailable.","commonSituations":"Fresh install with no opencli browser session created; session closed between runs; running in CI/headless environment without browser support; session store corrupted.","solutions":["Start a browser session with the CLI's session/login command before running the video command","Re-authenticate if the session expired","Check that the browser automation backend (playwright/puppeteer) is installed and functional","Run interactively on a machine with a supported browser instead of a restricted CI environment"],"exampleFix":"// before\nopencli bilibili video BV1xx411c7mD\n// after\nopencli session start   # or the CLI's login/browser init command\nopencli bilibili video BV1xx411c7mD","handlingStrategy":"validation","validationCode":"// before invoking, verify a session exists\nconst session = await getSession();\nif (!session || !session.page) { console.error('Run the session/login command first'); process.exit(1); }","typeGuard":"null","tryCatchPattern":"try { await opencli.video(bvid); }\ncatch (e) {\n  if (e instanceof CommandExecutionError && e.message.includes('Browser session required')) { console.error('Start a browser session: opencli session start'); }\n  else throw e;\n}","preventionTips":["Always start/renew the browser session before video commands","Check session expiry in scripts and re-login automatically","Avoid running browser-dependent commands in environments without a browser","Surface a friendly hint in wrappers when this error appears"],"tags":["browser-session","authentication","bilibili"],"backgroundTag":"missing-browser-session","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}