jackwener/OpenCLI · error · CommandExecutionError

Browser session required for bilibili summary

Error message

Browser session required for bilibili summary

What it means

The bilibili summary command requires an authenticated browser session (page) because it calls Bilibili web APIs with cookies and WBI signing via apiGet(page, ...). If page is null/falsy — the command was run without a logged-in browser session — this CommandExecutionError is thrown up front.

Source

Thrown at clis/bilibili/summary.js:142

        }
    }
    return rows;
}

var command = cli({
    site: 'bilibili',
    name: 'summary',
    access: 'read',
    description: '获取 B站视频的官方 AI 总结(视频页「AI总结」同款,含分段大纲与时间戳)',
    domain: 'www.bilibili.com',
    strategy: Strategy.COOKIE,
    args: [
        { name: 'bvid', required: true, positional: true, help: 'Video BV ID / URL / b23.tv short link' },
    ],
    columns: ['time', 'content'],
    func: async (page, kwargs) => {
        if (!page) {
            throw new CommandExecutionError('Browser session required for bilibili summary');
        }
        const bvid = await readBvid(kwargs.bvid);
        const view = await apiGet(page, '/x/web-interface/view', { params: { bvid } });
        const viewData = requireOkPayload(view, 'view');
        const cid = viewData?.cid;
        const upMid = viewData?.owner?.mid;
        if (!cid || !upMid) {
            throw new CommandExecutionError(`Bilibili view API did not return cid/up_mid for ${bvid}`);
        }
        const conclusion = await apiGet(page, '/x/web-interface/view/conclusion/get', {
            params: { bvid, cid, up_mid: upMid },
            signed: true,
        });
        const conclusionData = requireOkPayload(conclusion, 'conclusion');
        return rowsFromModel(readModelResult(conclusionData, bvid));
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Start the browser session and log in to Bilibili before running the summary command (the standard CLI login/init command).
  2. Re-run the command inside the same session where cookies are stored.
  3. If calling func directly, pass a real logged-in page object instead of null.
  4. For headless automation, use the library's persistent browser context with saved cookies.
  5. Check the CLI docs for the required session bootstrap step.

Example fix

// before
await run('bilibili', 'summary', bvid); // no session started
// after
await login(); // establish browser session with cookies
await run('bilibili', 'summary', bvid);
Defensive patterns

Strategy: validation

Validate before calling

if (!page) {
  throw new Error('Start a browser session (login) before calling bilibili summary');
}

Type guard

function hasPage(p) {
  return !!p && typeof p.goto === 'function';
}

Try / catch

try {
  const model = await readModelResult(page, bvid);
} catch (e) {
  if (String(e.message).includes('Browser session required')) {
    await login();
    return readModelResult(await getSessionPage(), bvid);
  }
  throw e;
}

Prevention

When it happens

Trigger: Invoking `bilibili summary <bvid>` without starting the CLI's browser/login session, or calling the exported func directly with page=null (e.g. in tests or scripted use).

Common situations: Running the command in headless/CI environments without the browser login step; forgetting `--session`/login flow; calling the command's func programmatically without supplying a page object.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/fe3b0e56ecefa7aa. Report an issue: GitHub.