{"record":{"id":"3247ec56114a91f7","repo":"jackwener/OpenCLI","slug":"facebook-notifications","errorCode":null,"errorMessage":"facebook/notifications","messagePattern":"facebook/notifications","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"error","filePath":"clis/facebook/notifications.js","lineNumber":302,"sourceCode":"    }\n    let rows;\n    try {\n        rows = await page.evaluate(buildNotificationsScript(limit));\n    } catch (error) {\n        const message = error instanceof Error ? error.message : String(error);\n        if (/AUTH_REQUIRED/i.test(message)) {\n            throw new AuthRequiredError(\n                'facebook.com',\n                'Open Chrome and log in to Facebook before retrying',\n            );\n        }\n        throw new CommandExecutionError(\n            `Failed to read facebook notifications: ${message}`,\n            'facebook.com page may not have rendered or markup may have changed',\n        );\n    }\n    if (!Array.isArray(rows) || rows.length === 0) {\n        throw new EmptyResultError(\n            'facebook/notifications',\n            'No notifications found — login session may have expired or you have no recent notifications',\n        );\n    }\n    return rows;\n}\n\nexport const notificationsCommand = cli({\n    site: 'facebook',\n    name: 'notifications',\n    access: 'read',\n    description: 'Get recent Facebook notifications (含 unread / time / url / notif_id / notif_type 列)',\n    domain: 'www.facebook.com',\n    strategy: Strategy.COOKIE,\n    browser: true,\n    navigateBefore: false,\n    args: [\n        {","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/facebook/notifications.js#L284-L320","documentation":"CommandExecutionError thrown by getFacebookNotifications when extracting notifications from the facebook.com page fails. The library wraps the error because scraping depends on Facebook's DOM, which may not render or may have changed. It carries a hint that the page may not have rendered or the markup may have changed. An EmptyResultError variant is thrown instead when extraction succeeded but returned no rows.","triggerScenarios":"Running the facebook/notifications command when page.evaluate/extraction throws: the notifications page failed to load, the DOM selectors no longer match, or the page render timed out.","commonSituations":"Facebook ships a markup change breaking selectors; slow network causing the page not to render in time; login redirect or checkpoint page shown instead of notifications; browser extension/browser disconnected mid-run.","solutions":["Re-run the command — transient render delays are the most common cause","Log in to facebook.com in the connected browser to refresh an expired session","Check the connected browser extension is running and reachable","Update the library in case Facebook changed its notifications markup and selectors were fixed","Verify network access to facebook.com"],"exampleFix":"// before: swallowing navigation errors so extraction runs on a blank page\nawait page.goto('https://www.facebook.com/notifications');\nconst rows = await page.evaluate(extractNotifications);\n// after: ensure page settles and handle the error explicitly\nawait page.goto('https://www.facebook.com/notifications', { settleMs: 4000 });\ntry {\n  const rows = await page.evaluate(extractNotifications);\n} catch (err) {\n  throw new CommandExecutionError(\n    `Failed to read facebook notifications: ${err.message}`,\n    'facebook.com page may not have rendered or markup may have changed',\n  );\n}","handlingStrategy":"try-catch","validationCode":"// Best-effort pre-checks before calling\nif (typeof navigator !== 'undefined' && !navigator.onLine) throw new Error('offline');\n// Ensure an authenticated facebook.com session exists in the connected browser before scraping","typeGuard":"function isCommandExecutionError(e) {\n  return e instanceof Error && e.name === 'CommandExecutionError';\n}","tryCatchPattern":"try {\n  const rows = await getFacebookNotifications();\n} catch (err) {\n  if (/Failed to read facebook notifications/.test(err.message)) {\n    // wait and retry once for transient render delays\n    await new Promise(r => setTimeout(r, 3000));\n    return getFacebookNotifications();\n  }\n  throw err;\n}","preventionTips":["Keep an active facebook.com login in the driven browser","Retry once with a delay to absorb render timing races","Keep the library updated for Facebook markup changes","Check browser extension connectivity before long scraping runs"],"tags":["scraping","dom-extraction","network","facebook"],"backgroundTag":"dom-extraction-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}