jackwener/OpenCLI · error · CommandExecutionError
Xiaohongshu search rendered in a collapsed tab, but this bro
Error message
Xiaohongshu search rendered in a collapsed tab, but this browser session cannot replace the failed target.
What it means
When the first harvest's diagnostics show a 'collapsed' render (isCollapsedRender), command() calls replaceCollapsedTab to recover by opening the search URL in a fresh tab and closing the broken one. That recovery requires the browser session (Browser Bridge) to expose tab-management APIs: getActivePage, newTab, setActivePage, selectTab, closeTab. If any is missing, this CommandExecutionError is thrown because the session type cannot perform the replacement.
Source
Thrown at clis/xiaohongshu/search.js:813
throw new TimeoutError('xiaohongshu search content', CONTENT_WAIT_SECONDS);
}
if (waitResult !== 'content') {
throw new CommandExecutionError('Unexpected Xiaohongshu search wait payload shape.');
}
requireFilterApplication(await page.evaluate(buildApplySearchFiltersJs(requestedFilters)));
const harvestOptions = harvestOptionsForLimit(limit);
const harvest = requireHarvestPayload(await page.evaluate(buildScrollHarvestJs('www.xiaohongshu.com', limit, harvestOptions)), 'www.xiaohongshu.com');
if (harvest.diag.securityBlock) {
throw new CliError('SECURITY_BLOCK', 'Xiaohongshu search was blocked by request-frequency or security controls.', 'Wait before retrying or use a different logged-in browser session.');
}
return harvest;
}
async function replaceCollapsedTab(page, url) {
if (typeof page.getActivePage !== 'function' || typeof page.newTab !== 'function' ||
typeof page.setActivePage !== 'function' || typeof page.selectTab !== 'function' ||
typeof page.closeTab !== 'function') {
throw new CommandExecutionError(
'Xiaohongshu search rendered in a collapsed tab, but this browser session cannot replace the failed target.',
'Retry the command in a Browser Bridge session that supports tab replacement.',
);
}
const previousPage = page.getActivePage();
if (!previousPage) {
throw new CommandExecutionError('Xiaohongshu search cannot identify the collapsed browser target for safe replacement.');
}
let freshPage;
try {
freshPage = await page.newTab(url);
if (!freshPage) {
throw new Error('newTab returned no page identity');
}
page.setActivePage(freshPage);
await page.closeTab(previousPage);
}
catch (error) {View on GitHub (pinned to 49907e53dc)
Solutions
- Run the command in a full Browser Bridge session that supports multi-tab management (the remedy named in the error hint).
- Upgrade the CLI and its browser-bridge package to matching versions so the session wrapper exposes all five tab methods.
- If embedding programmatically, pass a page/session object implementing getActivePage, newTab, setActivePage, selectTab, and closeTab.
- Retry later if the collapse is transient — the collapsed render may not recur, avoiding the recovery path entirely.
Example fix
// before: minimal session lacking tab APIs
const session = await openSession({ tabs: false });
await run('xiaohongshu search', 'coffee');
// after: full browser-bridge session with tab support
const session = await openBridgeSession({ tabManagement: true });
await run('xiaohongshu search', 'coffee'); Defensive patterns
Strategy: fallback
Validate before calling
// Verify the session supports tab replacement before running search
const required = ['getActivePage', 'newTab', 'setActivePage', 'selectTab', 'closeTab'];
const missing = required.filter((m) => typeof page[m] !== 'function');
if (missing.length) throw new Error(`Session lacks tab APIs: ${missing.join(', ')}; use a Browser Bridge session`); Type guard
function supportsTabReplacement(page) {
return ['getActivePage', 'newTab', 'setActivePage', 'selectTab', 'closeTab']
.every((m) => typeof page?.[m] === 'function');
} Try / catch
try {
rows = await cli('xiaohongshu search', query);
} catch (err) {
if (err instanceof CommandExecutionError && /cannot replace the failed target/.test(err.message)) {
throw new Error('Use a full Browser Bridge session with tab management for xiaohongshu search');
}
throw err;
} Prevention
- Run the CLI inside a full Browser Bridge session with multi-tab support, not a bare single-page driver.
- Check supportsTabReplacement(page) programmatically before invoking search in embedded scripts.
- Keep CLI and browser-bridge versions in sync so the session wrapper exposes all tab methods.
- In tests, mock pages must implement the five tab APIs if they exercise the collapsed-render path.
When it happens
Trigger: replaceCollapsedTab(page, url) detects typeof page.getActivePage !== 'function' || typeof page.newTab !== 'function' || typeof page.setActivePage !== 'function' || typeof page.selectTab !== 'function' || typeof page.closeTab !== 'function' (clis/xiaohongshu/search.js:810-812) — i.e. a minimal/single-page session object lacking tab APIs while the page rendered collapsed.
Common situations: Running the CLI against a plain Playwright/Puppeteer page or a reduced headless session instead of a full Browser Bridge session; an older CLI/browser-bridge version whose session wrapper predates the tab API; embedding the command's func with a stubbed/mock page object in tests.
Related errors
- Xiaohongshu search cannot identify the collapsed browser tar
- Browser session required for xiaohongshu follow
- 12306 whoami failed: ${probe.detail}
- Browser session required for bilibili comment
- Browser session required for bilibili comments
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/9edf8d790ee41946.
Report an issue: GitHub.