{"record":{"id":"bdf1c9a6e1f0b1f7","repo":"jackwener/OpenCLI","slug":"failed-to-fetch-tiktok-studio-item-list-geterro","errorCode":null,"errorMessage":"Failed to fetch TikTok Studio item_list: ${getErrorMessage(error)}","messagePattern":"Failed to fetch TikTok Studio item_list: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/tiktok/creator-videos.js","lineNumber":188,"sourceCode":"    const url = username\n        ? `https://www.tiktok.com/@${encodeURIComponent(username)}/video/${encodeURIComponent(videoId)}`\n        : '';\n    return {\n        video_id: videoId,\n        title: String(item.desc ?? item.title ?? '').replace(/\\s+/g, ' ').trim(),\n        date: formatDate(item.post_time ?? item.create_time ?? item.schedule_time),\n        views: normalizeNumber(item.play_count),\n        likes: normalizeNumber(item.like_count),\n        comments: normalizeNumber(item.comment_count),\n        saves: normalizeNumber(item.favorite_count),\n        shares: normalizeNumber(item.share_count),\n        url,\n    };\n}\n\nasync function fetchCreatorVideosPage(page, cursor, size) {\n    const result = await page.evaluate(buildFetchItemListScript(buildItemListRequest(cursor, size))).catch((error) => {\n        throw new CommandExecutionError(`Failed to fetch TikTok Studio item_list: ${getErrorMessage(error)}`);\n    });\n    if (!result || typeof result !== 'object') {\n        throw new CommandExecutionError('TikTok Studio item_list returned an unreadable response');\n    }\n    if (result.networkError) {\n        throw new CommandExecutionError(`TikTok Studio item_list network failure: ${result.networkError}`);\n    }\n    if (result.status === 401 || result.status === 403) {\n        throw new AuthRequiredError('www.tiktok.com', `TikTok Studio item_list requires login (HTTP ${result.status})`);\n    }\n    if (!result.ok) {\n        const detail = result.parseError\n            ? `invalid JSON (${result.parseError})`\n            : `HTTP ${result.status || 0}${result.statusText ? ` ${result.statusText}` : ''}`;\n        throw new CommandExecutionError(`TikTok Studio item_list failed: ${detail}`, result.text ? `Response preview: ${result.text}` : undefined);\n    }\n    const payload = unwrapPayload(result.data);\n    assertApiSuccess(payload);","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/tiktok/creator-videos.js#L170-L206","documentation":"fetchCreatorVideosPage runs an in-page fetch against TikTok Studio's item_list API inside the browser context. If page.evaluate itself rejects (script threw, page crashed, navigation destroyed the context), the catch rethrows it as a CommandExecutionError wrapping the original message. This is the top-level failure boundary for the item_list RPC.","triggerScenarios":"page.evaluate rejects: the injected fetch script throws a non-network error, the page navigates/reloads mid-call, the Puppeteer/Playwright page or context is closed, or the browser tab crashed during the request.","commonSituations":"Chrome profile closed mid-run, TikTok triggering a full page navigation (login redirect) while the script runs, headless detection killing the tab, or long page.evaluate exceeding browser stability on heavy Studio pages.","solutions":["Read the wrapped getErrorMessage(error) detail to identify the root cause (context destroyed vs script throw)","Ensure the Chrome profile is logged in to TikTok Studio before running the command","Re-run the command; transient navigation or tab crashes are often one-off","Update Puppeteer/Playwright and keep the page idle (no concurrent navigation) during the call","Catch CommandExecutionError in the caller and retry with a fresh page"],"exampleFix":"// before\nconst result = await page.evaluate(buildFetchItemListScript(buildItemListRequest(cursor, size)));\n// after\nlet result;\ntry {\n  result = await page.evaluate(buildFetchItemListScript(buildItemListRequest(cursor, size)));\n} catch (error) {\n  await sleep(1000); // or reopen the page\n  result = await page.evaluate(buildFetchItemListScript(buildItemListRequest(cursor, size)));\n}","handlingStrategy":"try-catch","validationCode":"if (!page || page.isClosed?.()) throw new Error('Page closed before fetching creator videos');","typeGuard":"function isFetchResult(v) { return !!v && typeof v === 'object'; }","tryCatchPattern":"try {\n  rows = await listCreatorVideos(page, opts);\n} catch (e) {\n  if (e instanceof CommandExecutionError && /item_list/.test(e.message)) {\n    await sleep(2000); rows = await listCreatorVideos(page, opts); // one retry\n  } else throw e;\n}","preventionTips":["Keep the browser page idle — avoid concurrent navigation during evaluate calls","Ensure the Chrome profile stays logged in to TikTok Studio","Retry transient evaluate failures with a small backoff","Keep Puppeteer/Playwright and the CLI library up to date"],"tags":["tiktok","puppeteer","network","command-execution"],"backgroundTag":"page-evaluate-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}