{"record":{"id":"d1c64a301caf86f9","repo":"jackwener/OpenCLI","slug":"tiktok-returned-no-notifications","errorCode":null,"errorMessage":"TikTok returned no notifications","messagePattern":"TikTok returned no notifications","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"warning","filePath":"clis/tiktok/notifications.js","lineNumber":123,"sourceCode":"}\n\nasync function listNotifications(page, args) {\n    const limit = requireLimit(args.limit, { fallback: DEFAULT_LIMIT, max: MAX_LIMIT });\n    const typeKey = requireNotificationType(args.type);\n    await page.goto('https://www.tiktok.com/foryou', { waitUntil: 'load', settleMs: 5000 });\n    let rows;\n    try {\n        rows = await page.evaluate(buildNotificationsScript(limit, typeKey));\n    } catch (error) {\n        throwTikTokPageContextError(error, {\n            authMessage: 'TikTok requires login to read notifications',\n            emptyPattern: /No notifications returned/,\n            emptyTarget: 'tiktok notifications',\n            failureMessage: 'Failed to load TikTok notifications',\n        });\n    }\n    if (!Array.isArray(rows) || rows.length === 0) {\n        throw new EmptyResultError('tiktok notifications', 'TikTok returned no notifications');\n    }\n    return rows;\n}\n\nexport const notificationsCommand = cli({\n    site: 'tiktok',\n    name: 'notifications',\n    access: 'read',\n    description: 'Read TikTok inbox notifications (likes, comments, mentions, followers) via page-context APIs',\n    domain: 'www.tiktok.com',\n    strategy: Strategy.COOKIE,\n    browser: true,\n    args: [\n        { name: 'limit', type: 'int', default: DEFAULT_LIMIT, help: `Number of notifications (max ${MAX_LIMIT})` },\n        {\n            name: 'type',\n            default: 'all',\n            help: 'Notification type',","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/tiktok/notifications.js#L105-L141","documentation":"This library's TikTok notifications command collects rows from a scraped page and throws EmptyResultError when the result is not a non-empty array. It exists so an empty/blocked fetch is reported explicitly instead of silently returning zero results. The companion failureMessage 'Failed to load TikTok notifications' and emptyPattern 'No notifications returned' are surfaced to the CLI user.","triggerScenarios":"listNotifications finished its scrape but `rows` is undefined, not an array, or an empty array — e.g. TikTok returned a page without notification markup, the session cookie is absent/expired, or a login/bot-wall page replaced the notifications DOM.","commonSituations":"Running without being logged into TikTok in the automation browser; TikTok A/B-changing the notifications page; rate-limiting returning a stub page; network hiccup yielding an empty payload.","solutions":["Verify the automation browser has an authenticated TikTok session (cookies present) before calling listNotifications","Re-run the command; transient blocks often resolve on retry after a delay","Check the returned page manually (save HTML/screenshot) to confirm whether TikTok changed the notifications markup","Upgrade the library in case selectors were updated for a newer TikTok page"],"exampleFix":"// before\nconst rows = await listNotifications();\nconsole.log(rows.length);\n// after\nlet rows;\ntry {\n  rows = await listNotifications();\n} catch (e) {\n  if (e.name === 'EmptyResultError') rows = [];\n  else throw e;\n}\nconsole.log(rows.length);","handlingStrategy":"try-catch","validationCode":"const session = await browser.cookies.get('tiktok.com', 'sessionid');\nif (!session) throw new Error('Not logged into TikTok: notifications require an authenticated session');","typeGuard":"function hasRows(v) {\n  return Array.isArray(v) && v.length > 0;\n}","tryCatchPattern":"let rows = [];\ntry {\n  rows = await listNotifications();\n} catch (e) {\n  if (e.name === 'EmptyResultError' || /no notifications/i.test(e.message)) {\n    console.warn('No TikTok notifications available (check login/session)');\n  } else {\n    throw e;\n  }\n}","preventionTips":["Persist a logged-in TikTok session in the automation browser before calling notification commands","Check sessionid cookie presence as a precondition","Treat empty results as data, not crashes: catch EmptyResultError and default to []","Cache the last good result to distinguish 'truly empty' from 'blocked'"],"tags":["tiktok","scraping","empty-result","auth"],"backgroundTag":"empty-result-set","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}