jackwener/OpenCLI · error · CommandExecutionError
Browser session required for bilibili comments
Error message
Browser session required for bilibili comments
What it means
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.
Source
Thrown at clis/bilibili/comments.js:118
}
cli({
site: 'bilibili',
name: 'comments',
access: 'read',
description: '获取 B站视频评论(官方 API;用 --parent <rpid> 读取某条评论下的「楼中楼」回复;用 --top 只看置顶评论)',
domain: 'www.bilibili.com',
strategy: Strategy.COOKIE,
args: [
{ name: 'bvid', required: true, positional: true, help: 'Video BV ID (e.g. BV1WtAGzYEBm)' },
{ name: 'parent', type: 'int', help: 'rpid of a comment — fetch the replies under it instead of top-level comments' },
{ name: 'top', type: 'boolean', default: false, help: '只返回置顶评论(与 --parent 互斥)' },
{ name: 'limit', type: 'int', default: 20, help: 'Number of comments (max 50)' },
],
columns: ['rank', 'rpid', 'author', 'text', 'likes', 'replies', 'time'],
func: async (page, kwargs) => {
if (!page) {
throw new CommandExecutionError('Browser session required for bilibili comments');
}
const limit = parseLimit(kwargs.limit);
const parent = parseParent(kwargs.parent);
const top = kwargs.top === true;
if (top && parent != null) {
throw new ArgumentError('bilibili comments --top cannot be combined with --parent (pinned comments only exist at the top level)');
}
let bvid;
try {
bvid = await resolveBvid(kwargs.bvid);
}
catch (error) {
throw new ArgumentError(`Cannot resolve Bilibili BV ID from input: ${String(kwargs.bvid ?? '')}`, error instanceof Error ? error.message : String(error));
}
// Resolve bvid → aid (required by reply API)
const view = await apiGet(page, '/x/web-interface/view', { params: { bvid } });
const viewData = requireOkPayload(view, 'view');
const aid = viewData?.aid;View on GitHub (pinned to 49907e53dc)
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
Defensive patterns
Strategy: validation
Validate before calling
if (!page) {
throw new Error('bilibili comments requires a browser session; initialize the CLI session first');
} Type guard
function hasBrowserSession(page) {
return !!page && typeof page.goto === 'function';
} Try / catch
try {
const rows = await bilibiliComments(bvid);
} catch (err) {
if (/Browser session required/.test(err.message)) {
// initialize the browser/cookie session and retry once
} else throw err;
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: CI environments without the browser/cookie layer; calling func(page, kwargs) directly in tests; browser session failed to launch before dispatch.
Related errors
- Browser session required for bilibili subtitle
- Browser session required for bilibili summary
- Browser session required for bilibili unfollow
- Browser session required for bilibili video
- Browser session required for linkedin salesnav-search
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/481a61ec22a1d0e5.
Report an issue: GitHub.