{"record":{"id":"17dfd37908ea95ca","repo":"jackwener/OpenCLI","slug":"instagram-login-required-before-posting","errorCode":null,"errorMessage":"Instagram login required before posting","messagePattern":"Instagram login required before posting","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/instagram/post.js","lineNumber":314,"sourceCode":"                    resetWindow = true;\n                }\n                catch {\n                    // Best-effort: a fresh automation window is safer than reusing a polluted one.\n                }\n            }\n            if (!resetWindow) {\n                await dismissResidualDialogs(input.page);\n                await input.page.wait({ time: 1 });\n            }\n        }\n    }\n    throw lastError instanceof Error ? lastError : new CommandExecutionError('Instagram post failed');\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');\n        throw new CommandExecutionError('Failed to open Instagram post composer');\n    }\n}\nasync function dismissResidualDialogs(page) {\n    for (let attempt = 0; attempt < 4; attempt++) {\n        const result = 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\n        const dialogs = Array.from(document.querySelectorAll('[role=\"dialog\"]'))","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/post.js#L296-L332","documentation":"ensureComposerOpen runs an in-page script (buildEnsureComposerOpenJs) that detects the Instagram login route or a visible username/password form plus a login button. When detected it returns {reason:'auth'} and the wrapper throws AuthRequiredError for www.instagram.com, meaning the stored session cookie is missing or expired and posting cannot proceed.","triggerScenarios":"Executing the post command without a prior Instagram login; the session cookie expired or was invalidated (password change, logout elsewhere, Instagram security challenge); the page redirected to /accounts/login; the automation browser profile is fresh.","commonSituations":"Long-lived CI sessions whose cookies expired; logging into the account from another device forcing session invalidation; running with a cleaned/temporary browser profile; Instagram detecting automation and forcing re-authentication.","solutions":["Run the Instagram login flow for this CLI first to establish a session, then retry the post","Persist and reuse the browser profile/cookies between runs so the session survives","Log in manually in the automation browser if challenged, complete any 2FA/verification, then retry","If cookies are supplied externally, refresh them from a logged-in browser session","Check Instagram account security emails — a forced logout invalidates stored sessions"],"exampleFix":"// before\nawait executeUiInstagramPost(kwargs); // fresh profile, not logged in -> AuthRequiredError\n// after\nawait cli.instagram.login({ headless: false }); // establish session first\nawait executeUiInstagramPost(kwargs);","handlingStrategy":"try-catch","validationCode":"// Check the session is alive before posting\nconst page = await getSessionPage();\nawait page.goto('https://www.instagram.com/', { waitUntil: 'networkidle' });\nif (/\\/accounts\\/login/.test(new URL(page.url()).pathname)) {\n  throw new Error('Instagram session expired — log in first');\n}","typeGuard":"function isAuthRequiredError(e) {\n  return e instanceof Error && (e.name === 'AuthRequiredError'\n    || /login required/i.test(e.message));\n}","tryCatchPattern":"try {\n  await executeUiInstagramPost(kwargs);\n} catch (e) {\n  if (isAuthRequiredError(e)) {\n    await runInstagramLogin(); // interactive login / refresh cookies\n    await executeUiInstagramPost(kwargs);\n  } else throw e;\n}","preventionTips":["Persist the browser profile so cookies survive across runs","Re-authenticate proactively before long CI jobs (cookies expire within weeks)","Never share one account session across many parallel automation runs","Handle Instagram security challenges/2FA promptly — they invalidate stored sessions"],"tags":["auth","instagram","session-expired"],"backgroundTag":"auth-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}