jackwener/OpenCLI · error · CommandExecutionError
Failed to read facebook search results: ${err instanceof Err
Error message
Failed to read facebook search results: ${err instanceof Error ? err.message : err} What it means
CommandExecutionError thrown by searchFacebook when page.evaluate running the search extraction script throws. Navigation succeeded, but executing buildSearchExtractScript in the page context failed, typically because the page did not render results or the markup changed. The library wraps the raw error with a hint rather than letting it propagate.
Source
Thrown at clis/facebook/search.js:160
const limit = requireLimit(kwargs.limit ?? 10);
// Navigate home first so the SPA is warm, then to the search results.
// Regression guard for #625: extraction must run *after* this navigation.
try {
await page.goto(FACEBOOK_HOME);
await page.goto(`https://www.facebook.com/search/top?q=${encodeURIComponent(query)}`, { settleMs: 4000 });
} catch (err) {
throw new CommandExecutionError(
`Failed to open facebook search: ${err instanceof Error ? err.message : err}`,
'Check that facebook.com is reachable and the browser extension is connected.',
);
}
let payload;
try {
payload = unwrapBrowserResult(await page.evaluate(buildSearchExtractScript(limit)));
} catch (err) {
throw new CommandExecutionError(
`Failed to read facebook search results: ${err instanceof Error ? err.message : err}`,
'Facebook may not have rendered or the search markup may have changed.',
);
}
if (!payload || typeof payload !== 'object' || !Array.isArray(payload.rows)) {
throw new CommandExecutionError('facebook search returned malformed extraction payload');
}
if (payload.status === 'auth') {
throw new AuthRequiredError('www.facebook.com', 'Open Chrome and log in to Facebook before retrying.');
}
if (payload.rows.length > 0) return payload.rows;
const d = payload.diagnostics || {};
if (d.anchorCount || d.mainTextLength > 200) {
throw new CommandExecutionError(
'facebook search page rendered but no entity results could be extracted',
`Diagnostics: feed=${!!d.feedFound}, anchors=${d.anchorCount || 0}, mainTextLength=${d.mainTextLength || 0}.`,View on GitHub (pinned to 49907e53dc)
Solutions
- Re-run the command — timing/render races are the most common cause
- Log in to facebook.com and confirm search results load manually in the browser
- Increase the settle time or retry after a delay so the SPA finishes rendering
- Update the library in case Facebook changed its search markup and the extract script was fixed
- Confirm the browser extension connection is stable
Example fix
// before: extracting immediately with no render allowance
payload = unwrapBrowserResult(await page.evaluate(buildSearchExtractScript(limit)));
// after: allow render time and handle evaluation failure
await page.goto(searchUrl, { settleMs: 4000 });
try {
payload = unwrapBrowserResult(await page.evaluate(buildSearchExtractScript(limit)));
} catch (err) {
throw new CommandExecutionError(
`Failed to read facebook search results: ${err.message}`,
'Facebook may not have rendered or the search markup may have changed.',
);
} Defensive patterns
Strategy: try-catch
Validate before calling
// After navigation, wait for results container before extracting
await page.waitForSelector('[role="feed"], [data-testid="search"]', { timeout: 10000 }).catch(() => {}); Type guard
function isExtractionFailure(e) {
return e instanceof Error && e.name === 'CommandExecutionError' &&
e.message.startsWith('Failed to read facebook search results');
} Try / catch
try {
const results = await searchFacebook(query, limit);
} catch (err) {
if (/Failed to read facebook search results/.test(err.message)) {
await new Promise(r => setTimeout(r, 3000));
return searchFacebook(query, limit); // one retry for render races
}
throw err;
} Prevention
- Allow adequate settle time for the SPA to render before extraction
- Confirm search results render when logged in, not a login wall
- Retry once — extraction races are usually transient
- Keep the library updated since Facebook markup changes break extract scripts
When it happens
Trigger: page.evaluate(unwrapBrowserResult(await ...)) throws while extracting search rows: evaluation timeout, execution context destroyed by SPA navigation, script erroring on unexpected DOM, or the browser disconnecting between navigation and extraction.
Common situations: Facebook login wall or checkpoint replacing results; SPA re-render destroying the execution context; slow network so results never render before extraction; Facebook DOM changes breaking the extract script selectors; browser tab closed mid-run.
Related errors
- facebook/notifications
- Unexpected Boss probe: ${JSON.stringify(probe)}
- Ctrip round-trip flight DOM extraction returned malformed ro
- Ctrip round-trip flight cards rendered but parser did not fi
- Ctrip round-trip flight rows were missing required airline/f
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/9f02348a9b44d7aa.
Report an issue: GitHub.