{"record":{"id":"10a533002bed702d","repo":"jackwener/OpenCLI","slug":"instagram-login-required-before-posting-a-reel","errorCode":null,"errorMessage":"Instagram login required before posting a reel","messagePattern":"Instagram login required before posting a reel","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/instagram/reel.js","lineNumber":71,"sourceCode":"}\nfunction prepareVideoUpload(filePath) {\n    const baseName = path.basename(filePath);\n    if (/^[a-zA-Z0-9._-]+$/.test(baseName)) {\n        return { originalPath: filePath, uploadPath: filePath };\n    }\n    const uploadPath = buildSafeTempVideoPath(filePath);\n    fs.copyFileSync(filePath, uploadPath);\n    return {\n        originalPath: filePath,\n        uploadPath,\n        cleanupPath: uploadPath,\n    };\n}\nasync function ensureComposerOpen(page) {\n    const result = await page.evaluate(buildEnsureComposerOpenJs());\n    if (!result?.ok) {\n        if (result?.reason === 'auth') {\n            throw new AuthRequiredError('www.instagram.com', 'Instagram login required before posting a reel');\n        }\n        throw new CommandExecutionError('Failed to open Instagram reel composer');\n    }\n    for (let attempt = 0; attempt < 12; attempt += 1) {\n        const ready = await page.evaluate(`\n      (() => {\n        const isVisible = (el) => {\n          if (!(el instanceof HTMLElement)) return false;\n          const style = window.getComputedStyle(el);\n          const rect = el.getBoundingClientRect();\n          return style.display !== 'none'\n            && style.visibility !== 'hidden'\n            && rect.width > 0\n            && rect.height > 0;\n        };\n        const inputs = Array.from(document.querySelectorAll('input[type=\"file\"]'))\n          .filter((el) => el instanceof HTMLInputElement)\n          .filter((el) => {","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/reel.js#L53-L89","documentation":"ensureComposerOpen runs in-page JavaScript (buildEnsureComposerOpenJs) to open Instagram's new-post/reel composer. When the page reports reason 'auth', the session is not logged in, and the library throws AuthRequiredError for www.instagram.com. Instagram only allows reel posting from an authenticated session, so this is a hard requirement.","triggerScenarios":"Evaluating the composer-open script against a page where the user is logged out — no session cookies, expired Instagram session, incognito profile without login, or the page redirected to the login screen.","commonSituations":"Fresh browser profile never logged in, Instagram invalidated the session (password change, security checkpoint), cookies cleared between runs, or automation environment where the login step was skipped.","solutions":["Log into www.instagram.com in the browser session before running the reel command.","Use a persistent browser profile that retains the Instagram session cookies.","Re-authenticate if Instagram expired/invalidated the session (check for login prompts).","Add a login/health-check step (e.g. gotoInstagramHome and verify logged-in state) prior to posting."],"exampleFix":"// before\nawait runReel(args); // assumes already logged in\n// after\nawait gotoInstagramHome(page);\nif (!(await isLoggedIn(page))) await performInstagramLogin(page);\nawait runReel(args);","handlingStrategy":"try-catch","validationCode":"await gotoInstagramHome(page);\nconst loggedIn = await page.evaluate(\"() => !!document.querySelector('svg[aria-label], nav a[href=\\\"/\\\"]') && !location.pathname.startsWith('/accounts/login')\");\nif (!loggedIn) throw new Error('Instagram session not logged in; authenticate first');","typeGuard":null,"tryCatchPattern":"try { await reel(args); } catch (e) { if (e.name === 'AuthRequiredError' || /login required/i.test(e.message)) { await performInstagramLogin(page); return reel(args); } throw e; }","preventionTips":["Use a persistent browser profile that keeps Instagram cookies","Verify logged-in state before any posting command","Re-login proactively when sessions expire","Avoid clearing cookies between automation runs"],"tags":["authentication","instagram","browser-session"],"backgroundTag":"auth-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}