{"record":{"id":"b5666b538e958b7d","repo":"jackwener/OpenCLI","slug":"failed-to-open-facebook-search-err-instanceof-e","errorCode":null,"errorMessage":"Failed to open facebook search: ${err instanceof Error ? err.message : err}","messagePattern":"Failed to open facebook search: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/facebook/search.js","lineNumber":150,"sourceCode":"        feedFound: !!document.querySelector('[role=\"feed\"]'),\n        anchorCount: anchors.length,\n        mainTextLength: clean((document.querySelector('[role=\"main\"]') || {}).textContent).length,\n      },\n    };\n  })()`;\n}\n\nasync function searchFacebook(page, kwargs) {\n  const query = requireQuery(kwargs.query);\n  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  }","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/facebook/search.js#L132-L168","documentation":"CommandExecutionError thrown by searchFacebook when navigating to facebook.com or the search results URL fails. The library first goes to the Facebook home page to warm the SPA, then to /search/top?q=..., and wraps any navigation error with a hint to check reachability and the browser extension connection. Extraction never runs if navigation fails.","triggerScenarios":"page.goto to FACEBOOK_HOME or the encoded /search/top?q=<query> URL throws: network outage, DNS failure, timeout, or the browser extension/page is disconnected or closed.","commonSituations":"Corporate proxy or firewall blocking facebook.com; offline machine; browser extension not connected after a browser restart; page navigated away or closed mid-command; very slow connection exceeding the settle timeout.","solutions":["Verify facebook.com is reachable in the connected browser (open it manually)","Reconnect/restart the browser extension that the CLI drives","Check network connectivity, proxy, and firewall settings","Re-run the command — transient network blips are common","Check for an expired Facebook login redirecting to an error page"],"exampleFix":"// before: assuming navigation always succeeds\nawait page.goto(`https://www.facebook.com/search/top?q=${q}`);\n// after: guard navigation and surface a actionable hint\ntry {\n  await page.goto(FACEBOOK_HOME);\n  await page.goto(`https://www.facebook.com/search/top?q=${encodeURIComponent(q)}`, { settleMs: 4000 });\n} catch (err) {\n  throw new CommandExecutionError(\n    `Failed to open facebook search: ${err.message}`,\n    'Check that facebook.com is reachable and the browser extension is connected.',\n  );\n}","handlingStrategy":"try-catch","validationCode":"// Reachability pre-check\nconst ok = await fetch('https://www.facebook.com', { method: 'HEAD' })\n  .then(r => r.ok).catch(() => false);\nif (!ok) throw new Error('facebook.com is not reachable — check network/extension');","typeGuard":"function isNavigationFailure(e) {\n  return e instanceof Error && e.name === 'CommandExecutionError' &&\n    e.message.startsWith('Failed to open facebook search');\n}","tryCatchPattern":"try {\n  const results = await searchFacebook(query, limit);\n} catch (err) {\n  if (/Failed to open facebook search/.test(err.message)) {\n    // retry after confirming connectivity/extension\n    await new Promise(r => setTimeout(r, 5000));\n    return searchFacebook(query, limit);\n  }\n  throw err;\n}","preventionTips":["Verify the browser extension is connected before running commands","Confirm facebook.com is reachable from your network/proxy","Retry navigation failures with backoff","Keep the driven browser logged in so redirects don't break navigation"],"tags":["network","navigation","browser-extension","facebook"],"backgroundTag":"page-navigation-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}