{"record":{"id":"6a4e047cf470176c","repo":"jackwener/OpenCLI","slug":"browser-session-required-for-instagram-story","errorCode":null,"errorMessage":"Browser session required for instagram story","messagePattern":"Browser session required for instagram story","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/instagram/story.js","lineNumber":12,"sourceCode":"import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport { ArgumentError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { publishStoryViaPrivateApi, resolveInstagramPrivatePublishConfig, } from './_shared/private-publish.js';\nimport { resolveCurrentUserId, resolveInstagramRuntimeInfo } from './_shared/runtime-info.js';\nimport { INSTAGRAM_HOME_URL } from './_shared/navigation.js';\nconst SUPPORTED_STORY_IMAGE_EXTENSIONS = new Set(['.jpg', '.jpeg', '.png', '.webp']);\nconst SUPPORTED_STORY_VIDEO_EXTENSIONS = new Set(['.mp4']);\nfunction requirePage(page) {\n    if (!page)\n        throw new CommandExecutionError('Browser session required for instagram story');\n    return page;\n}\nfunction validateInstagramStoryArgs(kwargs) {\n    if (kwargs.media === undefined) {\n        throw new ArgumentError('Argument \"media\" is required.', 'Provide --media /path/to/file.jpg or --media /path/to/file.mp4');\n    }\n}\nfunction normalizeStoryMediaItem(kwargs) {\n    const raw = String(kwargs.media ?? '').trim();\n    const parts = raw.split(',').map((part) => part.trim()).filter(Boolean);\n    if (parts.length === 0) {\n        throw new ArgumentError('Argument \"media\" is required.', 'Provide --media /path/to/file.jpg or --media /path/to/file.mp4');\n    }\n    if (parts.length > 1) {\n        throw new ArgumentError('Instagram story currently supports a single media item.', 'Provide one image or one video path with --media');\n    }\n    const resolved = path.resolve(parts[0]);\n    if (!fs.existsSync(resolved)) {","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/story.js#L1-L30","documentation":"A CommandExecutionError thrown by requirePage() in clis/instagram/story.js when no active browser (Puppeteer/Playwright) page is available. Posting a story requires a real logged-in browser session; the headless-fetch path used by other subcommands is not sufficient.","triggerScenarios":"registerThreadQuery calls requirePage(page) and page is undefined/null — i.e. the story command was invoked without first starting an authenticated browser session.","commonSituations":"Running `instagram story` before `instagram login`/browser launch, a crashed or closed browser, or programmatic use where the page handle was never created or was closed.","solutions":["Start an authenticated browser session (e.g. run the login command) before invoking the story command","Check that the browser process is still running and the page handle is alive","In code, create/open the page (browser.newPage()) and pass it to the story command","Guard calls: if (!page) await openSession() before calling story functions"],"exampleFix":"// before\nawait postStory({ media: 'photo.jpg' }); // page is undefined\n// after\nconst page = await getSessionPage(); // launches/logs in if needed\nawait postStory({ page, media: 'photo.jpg' });","handlingStrategy":"validation","validationCode":"if (!page || typeof page.evaluate !== 'function') {\n  throw new Error('Open an authenticated browser session before running the story command');\n}","typeGuard":"function isPage(p) { return !!p && typeof p.evaluate === 'function' && typeof p.goto === 'function'; }","tryCatchPattern":"try {\n  await postStory({ page, media: file });\n} catch (e) {\n  if (/Browser session required/.test(e.message)) {\n    page = await launchAndLogin();\n    await postStory({ page, media: file });\n  } else throw e;\n}","preventionTips":["Always launch/login the browser session before story commands","Check page.isClosed() if reusing a page handle","Encapsulate session creation in a helper that auto-launches","Avoid closing the browser while a batch of story posts is pending"],"tags":["browser","session","puppeteer","instagram"],"backgroundTag":"browser-session-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}