{"record":{"id":"c865a3797515236c","repo":"jackwener/OpenCLI","slug":"browser-session-required-for-facebook-marketplace-c865a3","errorCode":null,"errorMessage":"Browser session required for facebook marketplace-listings","messagePattern":"Browser session required for facebook marketplace-listings","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/facebook/marketplace-listings.js","lineNumber":24,"sourceCode":"  if (!Number.isInteger(limit) || limit <= 0) {\n    throw new ArgumentError('facebook marketplace-listings --limit must be a positive integer');\n  }\n  return Math.min(limit, 100);\n}\n\ncli({\n  site: 'facebook',\n  name: 'marketplace-listings',\n    access: 'read',\n  description: 'List your Facebook Marketplace seller listings',\n  domain: 'www.facebook.com',\n  strategy: Strategy.COOKIE,\n  args: [\n    { name: 'limit', type: 'int', default: 20, help: 'Number of listings to return' },\n  ],\n  columns: ['index', 'title', 'price', 'status', 'listed', 'clicks', 'actions'],\n  func: async (page, args) => {\n    if (!page) throw new CommandExecutionError('Browser session required for facebook marketplace-listings');\n    const limit = normalizeLimit(args.limit);\n    await page.goto('https://www.facebook.com/marketplace/you/selling/');\n    await page.wait(4);\n\n    const result = await page.evaluate(String.raw`(() => {\n      const clean = (s) => String(s || '').replace(/\\u00a0/g, ' ').replace(/\\s+/g, ' ').trim();\n      const allText = document.body?.innerText || '';\n      if (/log in|sign in/i.test(allText) && !/Marketplace/i.test(allText)) {\n        return { authRequired: true, rows: [] };\n      }\n\n      const lines = allText.split(/\\n+/).map(clean).filter(Boolean);\n      const seen = new Set();\n      const out = [];\n      for (let i = 1; i < lines.length; i += 1) {\n        if (!/^(?:CA\\$|\\$)\\s*\\d+/.test(lines[i])) continue;\n        const title = lines[i - 1];\n        if (!title || /^(Hide|All listings|Needs attention|Marketplace|Selling)$/i.test(title)) continue;","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/facebook/marketplace-listings.js#L6-L42","documentation":"CommandExecutionError thrown when the command's func receives a null/undefined page. The facebook marketplace-listings command requires an active browser session (Strategy.COOKIE via a managed Chrome profile); without one the scrape cannot run at all, so it fails fast with this explicit message instead of a confusing page.goto TypeError.","triggerScenarios":"Invoking marketplace-listings in an environment where no browser session was launched or attached (e.g., missing/failed browser bootstrap, headless runner without the profile browser, page object not injected).","commonSituations":"Running the CLI outside the wrapper that starts Chrome with the Facebook profile; browser startup failed earlier but the command still executed; CI/container without the user-data-dir/profile mounted.","solutions":["Launch the managed browser session first (open Chrome with the required profile) and re-run the command","Check earlier logs for browser-launch failures and fix them (e.g. missing Chrome binary or profile path)","If embedding the library, ensure you pass a live `page` object into the command func","Avoid running this command in environments where the browser wrapper is disabled"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (!page || typeof page.goto !== 'function') {\n  throw new Error('Browser session required: launch the managed Chrome profile before running marketplace-listings');\n}","typeGuard":"const hasPage = (p) => !!p && typeof p.goto === 'function' && typeof p.evaluate === 'function';","tryCatchPattern":"try {\n  await runMarketplaceListings();\n} catch (e) {\n  if (/Browser session required/.test(e.message)) {\n    await launchManagedBrowser(); // then retry\n  } else throw e;\n}","preventionTips":["Always launch the managed browser/profile before invoking the command","Check browser-launch logs for earlier silent failures","Ensure CI containers mount the required user-data-dir/profile","Pass a live page object when embedding the library"],"tags":["browser-session","prerequisite","facebook"],"backgroundTag":"browser-session-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}