{"record":{"id":"f184055ebb983aee","repo":"jackwener/OpenCLI","slug":"browser-session-required-for-linkedin-jobs-prefere","errorCode":null,"errorMessage":"Browser session required for linkedin jobs-preferences","messagePattern":"Browser session required for linkedin jobs-preferences","errorType":"error_code","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/linkedin/jobs-preferences.js","lineNumber":97,"sourceCode":"    job_alerts: Array.isArray(alerts.job_alerts) ? alerts.job_alerts.map(normalizeWhitespace).filter(Boolean).join('; ') : '',\n    preferences_url: normalizeWhitespace(preferences.preferences_url),\n    alerts_url: normalizeWhitespace(alerts.alerts_url),\n    raw_preferences: preferenceText.slice(0, 1200),\n  };\n}\n\ncli({\n  site: 'linkedin',\n  name: 'jobs-preferences',\n  access: 'read',\n  description: 'Read visible LinkedIn Jobs preferences and alert settings without changing them',\n  domain: 'www.linkedin.com',\n  strategy: Strategy.COOKIE,\n  browser: true,\n  args: [],\n  columns: ['open_to_work', 'job_titles', 'locations', 'job_alerts', 'preferences_url', 'alerts_url', 'raw_preferences'],\n  func: async (page) => {\n    if (!page) throw new CommandExecutionError('Browser session required for linkedin jobs-preferences');\n    await page.goto(PREFERENCES_URL);\n    await page.wait(5);\n    await assertLinkedInAuthenticated(page, 'LinkedIn jobs-preferences');\n    const preferences = unwrapEvaluateResult(await page.evaluate(buildPreferencesScript()));\n    await page.goto(ALERTS_URL);\n    await page.wait(5);\n    await assertLinkedInAuthenticated(page, 'LinkedIn jobs-preferences alerts');\n    const alerts = unwrapEvaluateResult(await page.evaluate(buildAlertsScript()));\n    return [normalizePreferences(preferences, alerts)];\n  },\n});\n\nexport const __test__ = {\n  inferOpenToWork,\n  normalizePreferences,\n};\n","sourceCodeStart":79,"sourceCodeEnd":114,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/linkedin/jobs-preferences.js#L79-L114","documentation":"CommandExecutionError thrown at the top of the linkedin jobs-preferences func when the page argument is falsy. The command requires a logged-in browser session (browser:true, COOKIE strategy) and this guard prevents navigation attempts without one. It surfaces when the session layer failed to provide a page.","triggerScenarios":"Running jobs-preferences without a working browser session: missing/expired LinkedIn cookies, failed browser launch, or calling func(null) directly.","commonSituations":"Cookie store expired so login failed silently; headless CI missing Chromium; invoking the command handler in tests without a page stub.","solutions":["Run the command via the normal CLI entry so the session is established first","Refresh LinkedIn session cookies for www.linkedin.com","Fix browser launch issues (install Chromium, check sandbox flags) if the session fails to start","In tests, pass a page stub implementing goto/wait/evaluate"],"exampleFix":"// before\nawait cli.run('jobs-preferences'); // cookies expired, no session\n// after\nawait cli.refreshSession({ cookies: loadCookies('linkedin') });\nawait cli.run('jobs-preferences');","handlingStrategy":"try-catch","validationCode":"if (!page) {\n  throw new Error('Run linkedin jobs-preferences via the CLI so a browser session is started first');\n}","typeGuard":"function hasBrowserPage(page) {\n  return typeof page === 'object' && page !== null && typeof page.goto === 'function' && typeof page.wait === 'function' && typeof page.evaluate === 'function';\n}","tryCatchPattern":"try {\n  const result = await runCli(['linkedin', 'jobs-preferences']);\n} catch (err) {\n  if (String(err.message).includes('Browser session required')) {\n    await startBrowserSession({ cookies: loadLinkedInCookies() });\n    // retry the command\n  } else throw err;\n}","preventionTips":["Never invoke the browser:true command func directly without a page","Validate LinkedIn cookies (login flow) before batch runs","Ensure browser dependencies are installed in headless/CI environments","Monitor session initialization logs to catch silent launch failures"],"tags":["browser-session","linkedin","session-required"],"backgroundTag":"browser-session-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}