{"record":{"id":"5b43395d2c526187","repo":"jackwener/OpenCLI","slug":"browser-session-required-for-facebook-marketplace","errorCode":null,"errorMessage":"Browser session required for facebook marketplace-inbox","messagePattern":"Browser session required for facebook marketplace-inbox","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/facebook/marketplace-inbox.js","lineNumber":24,"sourceCode":"  if (!Number.isInteger(limit) || limit <= 0) {\n    throw new ArgumentError('facebook marketplace-inbox --limit must be a positive integer');\n  }\n  return Math.min(limit, 100);\n}\n\ncli({\n  site: 'facebook',\n  name: 'marketplace-inbox',\n    access: 'read',\n  description: 'List recent Facebook Marketplace buyer/seller conversations',\n  domain: 'www.facebook.com',\n  strategy: Strategy.COOKIE,\n  args: [\n    { name: 'limit', type: 'int', default: 20, help: 'Number of conversations to return' },\n  ],\n  columns: ['index', 'buyer', 'listing', 'snippet', 'time', 'unread'],\n  func: async (page, args) => {\n    if (!page) throw new CommandExecutionError('Browser session required for facebook marketplace-inbox');\n    const limit = normalizeLimit(args.limit);\n    await page.goto('https://www.facebook.com/marketplace/inbox/');\n    await page.wait(4);\n\n    const result = await page.evaluate(String.raw`(() => {\n      const clean = (s) => String(s || '').replace(/[\\u00a0\\u202f]/g, ' ').replace(/\\s+/g, ' ').trim();\n      const timeRe = /^(?:\\d{1,2}:\\d{2}\\s?(?:AM|PM|am|pm|上午|下午)?|Mon|Tue|Wed|Thu|Fri|Sat|Sun|Today|Yesterday|\\d+[mhdw]|\\d+\\s*(?:min|h|d|w))$/;\n      const text = document.body?.innerText || '';\n      if (/log in|sign in/i.test(text) && !/Marketplace/i.test(text)) {\n        return { authRequired: true, rows: [] };\n      }\n\n      const lines = text.split(/\\n+/).map(clean).filter(Boolean);\n      const out = [];\n      const seen = new Set();\n      const skipBuyer = /^(Marketplace|Browse all|Notifications|Inbox|Marketplace access|Buying|Selling|Create new listing|Create multiple listings|Location|Categories|Vehicles|Property Rentals|All|Pending payment|Paid|To be shipped|Shipped|Cash on delivery|Completed|Filter by label)$/i;\n      for (let i = 0; i < lines.length - 2; i += 1) {\n        const buyer = lines[i];","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/facebook/marketplace-inbox.js#L6-L42","documentation":"The marketplace-inbox command requires a live browser session; if the page object is null when func runs, it throws CommandExecutionError('Browser session required for facebook marketplace-inbox'). COOKIE strategy commands need a connected browser extension session with Facebook cookies.","triggerScenarios":"Invoking the command without an active browser session so the registry passes page = null into the command function — e.g. extension not connected, headed browser not launched, or headless mode without the session bridge.","commonSituations":"Running the CLI before starting the companion Chrome/extension; session died between runs; CI environment with no browser; forgetting to log in / launch the profile the CLI binds to.","solutions":["Launch the companion browser/extension session before running the command.","Verify the extension is connected (check the CLI's session/connection status if available).","In CI, set up the browser session (headed Chrome with the extension profile) as a prerequisite step.","Re-authenticate if the browser session expired or was closed."],"exampleFix":"// before\nawait cli.run(['facebook', 'marketplace-inbox']); // page null\n// after\nawait session.ensureBrowserConnected(); // start Chrome + extension first\nawait cli.run(['facebook', 'marketplace-inbox']);","handlingStrategy":"try-catch","validationCode":"// ensure the session exists before invoking\nconst hasSession = await session.isConnected(); // extension/bridge check\nif (!hasSession) await session.launchBrowser();","typeGuard":null,"tryCatchPattern":"try {\n  const items = await cli.run(['facebook', 'marketplace-inbox']);\n} catch (err) {\n  if (/Browser session required/.test(err.message)) {\n    await session.launchBrowser(); // start Chrome + extension, then retry\n  } else throw err;\n}","preventionTips":["Always launch the companion browser/extension before running browser-backed commands.","Check session/connection status in scripts as a pre-step.","In CI, provision the browser session as a prerequisite stage.","Reconnect the session if the browser was closed between runs."],"tags":["browser-session","prerequisite","facebook"],"backgroundTag":"browser-session-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}