jackwener/OpenCLI · error · CommandExecutionError
Xiaohongshu search cannot identify the collapsed browser tar
Error message
Xiaohongshu search cannot identify the collapsed browser target for safe replacement.
What it means
After confirming the session supports tab replacement, replaceCollapsedTab calls page.getActivePage() to snapshot which tab is collapsed so it can be safely closed after the new one is opened. If getActivePage() returns a falsy value, the function cannot know which target to replace and throws this CommandExecutionError rather than risking closing the wrong tab.
Source
Thrown at clis/xiaohongshu/search.js:820
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) {
const cleanupErrors = [];
if (freshPage) {
let restoredPrevious = false;
try {
await page.selectTab(previousPage);
restoredPrevious = true;
}View on GitHub (pinned to 49907e53dc)
Solutions
- Re-run the command in a fresh session — a lost active-page pointer usually only affects the current run.
- Ensure no other automation is concurrently opening/closing tabs in the same browser session.
- Check that the session wrapper registers an active page on goto; if using a custom session, call setActivePage after creating/navigating the page.
- Upgrade the browser-bridge version if the active-page tracking is known to be buggy.
Example fix
// before: custom session that never registers the active page
const page = await session.newTab(url);
await page.goto(url);
await run('xiaohongshu search', 'coffee');
// after: register the active page so recovery can identify the collapsed target
const page = await session.newTab(url);
await session.setActivePage(page);
await page.goto(url);
await run('xiaohongshu search', 'coffee'); Defensive patterns
Strategy: try-catch
Validate before calling
// Confirm the session has a registered active page before search
if (typeof session.getActivePage !== 'function' || !session.getActivePage()) {
throw new Error('Session has no active page; call setActivePage after opening the tab');
} Type guard
function hasActivePage(session) { return Boolean(session?.getActivePage?.()); } Try / catch
try {
rows = await cli('xiaohongshu search', query);
} catch (err) {
if (err instanceof CommandExecutionError && /cannot identify the collapsed browser target/.test(err.message)) {
// restart with a clean session so active-page state is rebuilt
await session.close();
session = await openBridgeSession({ tabManagement: true });
rows = await cli('xiaohongshu search', query);
} else { throw err; }
} Prevention
- Never close or detach the search tab from other automation while the command is running.
- Ensure setActivePage is called after opening tabs in custom session wrappers.
- Restart with a fresh session after this error — active-page state is not recoverable mid-run.
- Avoid concurrent scripts sharing one browser-bridge session.
When it happens
Trigger: In replaceCollapsedTab (clis/xiaohongshu/search.js:818-821): the session exposes all tab APIs, but page.getActivePage() returns null/undefined because the session has no currently-active page registered — e.g. the collapsed page was already detached, closed, or the session lost its active-page pointer mid-run.
Common situations: The target tab was closed externally (user or another automation step) between navigation and recovery; a session state bug where setActivePage was never called after goto; racing another script that manipulates tabs in the same browser-bridge session concurrently.
Related errors
- Xiaohongshu search rendered in a collapsed tab, but this bro
- 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/13a30a24144889d6.
Report an issue: GitHub.