{"record":{"id":"9f02348a9b44d7aa","repo":"jackwener/OpenCLI","slug":"failed-to-read-facebook-search-results-err-inst","errorCode":null,"errorMessage":"Failed to read facebook search results: ${err instanceof Error ? err.message : err}","messagePattern":"Failed to read facebook search results: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/facebook/search.js","lineNumber":160,"sourceCode":"  const limit = requireLimit(kwargs.limit ?? 10);\n\n  // Navigate home first so the SPA is warm, then to the search results.\n  // Regression guard for #625: extraction must run *after* this navigation.\n  try {\n    await page.goto(FACEBOOK_HOME);\n    await page.goto(`https://www.facebook.com/search/top?q=${encodeURIComponent(query)}`, { settleMs: 4000 });\n  } catch (err) {\n    throw new CommandExecutionError(\n      `Failed to open facebook search: ${err instanceof Error ? err.message : err}`,\n      'Check that facebook.com is reachable and the browser extension is connected.',\n    );\n  }\n\n  let payload;\n  try {\n    payload = unwrapBrowserResult(await page.evaluate(buildSearchExtractScript(limit)));\n  } catch (err) {\n    throw new CommandExecutionError(\n      `Failed to read facebook search results: ${err instanceof Error ? err.message : err}`,\n      'Facebook may not have rendered or the search markup may have changed.',\n    );\n  }\n\n  if (!payload || typeof payload !== 'object' || !Array.isArray(payload.rows)) {\n    throw new CommandExecutionError('facebook search returned malformed extraction payload');\n  }\n  if (payload.status === 'auth') {\n    throw new AuthRequiredError('www.facebook.com', 'Open Chrome and log in to Facebook before retrying.');\n  }\n  if (payload.rows.length > 0) return payload.rows;\n\n  const d = payload.diagnostics || {};\n  if (d.anchorCount || d.mainTextLength > 200) {\n    throw new CommandExecutionError(\n      'facebook search page rendered but no entity results could be extracted',\n      `Diagnostics: feed=${!!d.feedFound}, anchors=${d.anchorCount || 0}, mainTextLength=${d.mainTextLength || 0}.`,","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/facebook/search.js#L142-L178","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before: extracting immediately with no render allowance\npayload = unwrapBrowserResult(await page.evaluate(buildSearchExtractScript(limit)));\n// after: allow render time and handle evaluation failure\nawait page.goto(searchUrl, { settleMs: 4000 });\ntry {\n  payload = unwrapBrowserResult(await page.evaluate(buildSearchExtractScript(limit)));\n} catch (err) {\n  throw new CommandExecutionError(\n    `Failed to read facebook search results: ${err.message}`,\n    'Facebook may not have rendered or the search markup may have changed.',\n  );\n}","handlingStrategy":"try-catch","validationCode":"// After navigation, wait for results container before extracting\nawait page.waitForSelector('[role=\"feed\"], [data-testid=\"search\"]', { timeout: 10000 }).catch(() => {});","typeGuard":"function isExtractionFailure(e) {\n  return e instanceof Error && e.name === 'CommandExecutionError' &&\n    e.message.startsWith('Failed to read facebook search results');\n}","tryCatchPattern":"try {\n  const results = await searchFacebook(query, limit);\n} catch (err) {\n  if (/Failed to read facebook search results/.test(err.message)) {\n    await new Promise(r => setTimeout(r, 3000));\n    return searchFacebook(query, limit); // one retry for render races\n  }\n  throw err;\n}","preventionTips":["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"],"tags":["scraping","dom-extraction","page-evaluate","facebook"],"backgroundTag":"dom-extraction-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}