{"record":{"id":"7a88cee033c43865","repo":"jackwener/OpenCLI","slug":"browser-session-required","errorCode":null,"errorMessage":"Browser session required","messagePattern":"Browser session required","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/instagram/download.js","lineNumber":298,"sourceCode":"        const picked = pickNode(nodes[index], index);\n        if (!picked.ok) {\n          return { ok: false, errorCode: 'COMMAND_EXEC', error: picked.error };\n        }\n        items.push(picked.item);\n      }\n\n      return {\n        ok: true,\n        shortcode: media.code,\n        owner: media?.user?.username || '',\n        items,\n      };\n    })()\n  `;\n}\nfunction ensurePage(page) {\n    if (!page)\n        throw new CommandExecutionError('Browser session required');\n    return page;\n}\nfunction normalizeFetchResult(result) {\n    const unwrapped = unwrapEvaluateResult(result);\n    if (!unwrapped || typeof unwrapped !== 'object' || Array.isArray(unwrapped)) {\n        throw new CommandExecutionError('Failed to fetch Instagram media metadata');\n    }\n    if (typeof unwrapped.ok !== 'boolean') {\n        throw new CommandExecutionError('Instagram media metadata returned malformed result');\n    }\n    return unwrapped;\n}\nfunction handleFetchFailure(result) {\n    const message = result.error || 'Instagram media fetch failed';\n    if (result.errorCode === 'AUTH_REQUIRED') {\n        throw new AuthRequiredError('instagram.com', message);\n    }\n    if (result.errorCode === 'RATE_LIMITED') {","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/download.js#L280-L316","documentation":"Thrown by ensurePage when the browser page reference is null/undefined — i.e. no active browser session page exists to run the Instagram metadata fetch in. Callers must establish a browser page before invoking Instagram metadata operations.","triggerScenarios":"Calling browserPage-driven download flow when browser launch or page creation failed/was skipped, so page is falsy when ensurePage is called.","commonSituations":"Browser failed to launch (missing browser binary), session teardown ran before download, or code path invoked without initializing the browser session.","solutions":["Ensure the browser session is started and a page is created before downloading","Check browser launch errors earlier in the flow (missing browser, bad profile path)","Re-run the command so a fresh page is established"],"exampleFix":"// before\nconst page = maybeGetPage(); // undefined\nawait download(page);\n// after\nconst page = await launchBrowserAndGetPage();\nif (!page) throw ...; // or ensure the flow guarantees a page\nawait download(page);","handlingStrategy":"try-catch","validationCode":"const page = await browser.newPage();\nif (!page) throw new Error('Browser page could not be created before download');","typeGuard":"function hasPage(p) {\n  return !!p && typeof p.evaluate === 'function';\n}","tryCatchPattern":"try {\n  await igDownload(url);\n} catch (e) {\n  if (e.message === 'Browser session required') {\n    console.error('Initialize/relaunch the browser session before downloading.');\n  } else throw e;\n}","preventionTips":["Always launch the browser and create a page before calling download flows","Check for launch failures (missing browser binary, bad profile) early","Verify page lifetime — don't close the page before the download completes"],"tags":["browser-automation","session","initialization"],"backgroundTag":"browser-session-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}