{"record":{"id":"39a20d50e7c54386","repo":"jackwener/OpenCLI","slug":"failed-to-read-facebook-notifications-message","errorCode":null,"errorMessage":"Failed to read facebook notifications: ${message}","messagePattern":"Failed to read facebook notifications: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/facebook/notifications.js","lineNumber":296,"sourceCode":"    } catch (error) {\n        const message = error instanceof Error ? error.message : String(error);\n        throw new CommandExecutionError(\n            `Failed to navigate to facebook notifications: ${message}`,\n            'facebook.com may be unreachable',\n        );\n    }\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 列)',","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/facebook/notifications.js#L278-L314","documentation":"CommandExecutionError thrown when page.evaluate(buildNotificationsScript(limit)) fails for any reason other than AUTH_REQUIRED. The inner message is interpolated and a hint ('facebook.com page may not have rendered or markup may have changed') is attached, distinguishing page-structure failures from auth and navigation failures.","triggerScenarios":"The evaluate script throwing due to unexpected Facebook DOM (missing roles/selectors), script runtime errors, the page not rendering notification rows in time, or evaluate timing out/crashing.","commonSituations":"Facebook UI/markup update breaking the extraction helpers (stripMarkAsReadPrefix, extractNotificationRowsFromDoc); SPA still loading when the script ran; ad-blocker or extension altering the DOM; page crashed during evaluate.","solutions":["Read the interpolated inner message to identify the exact evaluate failure","Re-run after giving the page more time to render (SPA list items render late)","Reload the notifications page in the managed browser and verify rows render manually","If markup changed, update buildNotificationsScript/extract helpers to match current Facebook DOM"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Give the SPA time to render, then sanity-check the DOM before evaluate\nawait page.wait(3);\nconst rendered = await page.evaluate(String.raw`(() => !!document.querySelector('[role=\"listitem\"]'))()`);","typeGuard":null,"tryCatchPattern":"try {\n  const rows = await getFacebookNotifications(page, args);\n} catch (e) {\n  if (/Failed to read facebook notifications/.test(e.message)) {\n    // DOM/markup issue: re-run with longer wait or update extraction selectors\n    await page.reload(); await retryWithLongerWait();\n  } else throw e;\n}","preventionTips":["Inspect the interpolated inner message for the exact evaluate failure","Wait for list rows to render before scraping the SPA","Pin/update extraction selectors after Facebook markup changes","Disable extensions that mutate the DOM in the automation profile"],"tags":["scraping","dom-change","facebook"],"backgroundTag":"scrape-markup-changed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}