{"record":{"id":"1d7d3ec1ca61647e","repo":"jackwener/OpenCLI","slug":"browser-session-required-for-bilibili-follow","errorCode":null,"errorMessage":"Browser session required for bilibili follow","messagePattern":"Browser session required for bilibili follow","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/follow.js","lineNumber":61,"sourceCode":"cli({\n    site: 'bilibili',\n    name: 'follow',\n    access: 'write',\n    description: '关注 B站用户（官方 API，需登录）',\n    domain: 'www.bilibili.com',\n    strategy: Strategy.COOKIE,\n    args: [\n        {\n            name: 'target',\n            required: true,\n            positional: true,\n            help: '目标 UID / 用户名 / space.bilibili.com 链接',\n        },\n    ],\n    columns: ['mid', 'name', 'status', 'url'],\n    func: async (page, kwargs) => {\n        if (!page) {\n            throw new CommandExecutionError('Browser session required for bilibili follow');\n        }\n        const mid = await resolveTargetMid(page, kwargs.target);\n        const self = await getSelfUid(page);\n        if (mid === self) {\n            throw new ArgumentError('Cannot follow yourself');\n        }\n        const attribute = await fetchRelationAttribute(page, mid);\n        const url = `https://space.bilibili.com/${mid}`;\n        if (attribute === 2 || attribute === 6) {\n            return [{ mid, name: '', status: 'already-following', url }];\n        }\n        if (attribute === 128) {\n            throw new CommandExecutionError(\n                `Bilibili user ${mid} is blocked; unblock first before following.`,\n            );\n        }\n        // act=1 follow, act=2 unfollow. re_src=11 is the community-standard\n        // \"web\" source value used by third-party libs (bilibili-api-python etc.);","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/follow.js#L43-L79","documentation":"The follow command's func requires an authenticated browser page (cookies) to read your own UID and mutate relations. If the framework passes a falsy page (no browser session started / not logged in), the command short-circuits with this CommandExecutionError before doing any work.","triggerScenarios":"Running bilibili follow without an active browser session, or with a session that failed to start (browser crashed, no profile, headless setup missing).","commonSituations":"Running in CI without a logged-in browser profile, forgetting the login step of the CLI, or the browser being closed between commands.","solutions":["Start/log into the browser session before running the follow command (e.g. run the login/open command for this CLI suite).","Ensure cookies for bilibili.com are present in the browser profile.","In scripts, check session state before invoking follow."],"exampleFix":"// before\nawait run('bilibili follow --target 9469745');\n// after\nawait run('login');            // establish browser session first\nawait run('bilibili follow --target 9469745');","handlingStrategy":"validation","validationCode":"if (!session || !session.page) throw new Error('run login / open browser session first');","typeGuard":"function hasPage(ctx) {\n  return ctx != null && typeof ctx === 'object' && ctx.page != null;\n}","tryCatchPattern":"try {\n  await followCommand(page, kwargs);\n} catch (e) {\n  if (String(e.message).includes('Browser session required')) {\n    await login();\n    return followCommand(await getSessionPage(), kwargs);\n  }\n  throw e;\n}","preventionTips":["Always login before relation-mutating commands","Keep the browser process alive across CLI invocations","In CI, provision a logged-in browser profile or skip these commands","Check session state programmatically before batch runs"],"tags":["session","authentication","browser"],"backgroundTag":"missing-browser-session","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}