{"record":{"id":"288d8add8ee2d6dc","repo":"jackwener/OpenCLI","slug":"browser-session-required-for-instagram-note","errorCode":null,"errorMessage":"Browser session required for instagram note","messagePattern":"Browser session required for instagram note","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/instagram/note.js","lineNumber":9,"sourceCode":"import { ArgumentError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nconst INSTAGRAM_INBOX_URL = 'https://www.instagram.com/direct/inbox/';\nconst INSTAGRAM_NOTE_DOC_ID = '25155183657506484';\nconst INSTAGRAM_NOTE_MUTATION_NAME = 'usePolarisCreateInboxTrayItemSubmitMutation';\nconst INSTAGRAM_NOTE_ROOT_FIELD = 'xdt_create_inbox_tray_item';\nfunction requirePage(page) {\n    if (!page)\n        throw new CommandExecutionError('Browser session required for instagram note');\n    return page;\n}\nfunction validateInstagramNoteArgs(kwargs) {\n    if (kwargs.content === undefined) {\n        throw new ArgumentError('Argument \"content\" is required.', 'Provide a note text, for example: opencli instagram note \"hello\"');\n    }\n}\nfunction normalizeInstagramNoteContent(kwargs) {\n    const content = String(kwargs.content ?? '').trim();\n    if (!content) {\n        throw new ArgumentError('Instagram note content cannot be empty.', 'Provide a non-empty note text, for example: opencli instagram note \"hello\"');\n    }\n    if (Array.from(content).length > 60) {\n        throw new ArgumentError('Instagram note content must be 60 characters or fewer.', 'Shorten the note text and try again.');\n    }\n    return content;\n}\nfunction buildNoteSuccessResult(noteId) {","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/note.js#L1-L27","documentation":"requirePage guards every instagram note operation: posting a note is a browser-automation action that needs an active Puppeteer/Playwright page logged into Instagram. When page is null/undefined the CommandExecutionError 'Browser session required for instagram note' is thrown instead of dereferencing page and crashing with an opaque TypeError.","triggerScenarios":"Calling the instagram note command without first opening a browser session (page === null), or after the browser/page was closed before requirePage(page) is invoked inside browserPage.","commonSituations":"Running the CLI headless-scripted without the login/browser step; browser crashed or was closed between commands; forgetting the command that establishes the session; env where browser launch silently failed.","solutions":["Open a browser session (the CLI's browser/login command) before running instagram note","Log in to Instagram in that session so the direct inbox page is accessible","Check that the browser process is still alive; restart it if it crashed","Handle CommandExecutionError in wrapper scripts and prompt the user to open a session first"],"exampleFix":"// before\nawait postInstagramNote(null, { content: 'hello' }); // throws\n// after\nconst page = await getOrCreateBrowserPage(); // launches/logs in if needed\nawait postInstagramNote(requirePage(page), { content: 'hello' });","handlingStrategy":"try-catch","validationCode":"if (!page) {\n  throw new Error('Open a browser session and log in before running instagram note.');\n}","typeGuard":"function hasActivePage(p) {\n  return !!p && typeof p.goto === 'function' && !p.isClosed();\n}","tryCatchPattern":"try {\n  await instagramNote(ctx, { content: 'hello' });\n} catch (e) {\n  if (e.message === 'Browser session required for instagram note') {\n    console.error('No browser session. Run the browser/login command first, then retry.');\n  } else throw e;\n}","preventionTips":["Always establish the browser session before note commands","Check page.isClosed() before reuse if holding a page reference","Re-launch the browser after crashes instead of reusing a dead page","Wrap scripted flows to auto-open a session when missing"],"tags":["browser-session","prerequisite","instagram","command-execution"],"backgroundTag":"browser-session-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}