jackwener/OpenCLI · error · CommandExecutionError
Browser session required for facebook marketplace-listings
Error message
Browser session required for facebook marketplace-listings
What it means
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.
Source
Thrown at clis/facebook/marketplace-listings.js:24
if (!Number.isInteger(limit) || limit <= 0) {
throw new ArgumentError('facebook marketplace-listings --limit must be a positive integer');
}
return Math.min(limit, 100);
}
cli({
site: 'facebook',
name: 'marketplace-listings',
access: 'read',
description: 'List your Facebook Marketplace seller listings',
domain: 'www.facebook.com',
strategy: Strategy.COOKIE,
args: [
{ name: 'limit', type: 'int', default: 20, help: 'Number of listings to return' },
],
columns: ['index', 'title', 'price', 'status', 'listed', 'clicks', 'actions'],
func: async (page, args) => {
if (!page) throw new CommandExecutionError('Browser session required for facebook marketplace-listings');
const limit = normalizeLimit(args.limit);
await page.goto('https://www.facebook.com/marketplace/you/selling/');
await page.wait(4);
const result = await page.evaluate(String.raw`(() => {
const clean = (s) => String(s || '').replace(/\u00a0/g, ' ').replace(/\s+/g, ' ').trim();
const allText = document.body?.innerText || '';
if (/log in|sign in/i.test(allText) && !/Marketplace/i.test(allText)) {
return { authRequired: true, rows: [] };
}
const lines = allText.split(/\n+/).map(clean).filter(Boolean);
const seen = new Set();
const out = [];
for (let i = 1; i < lines.length; i += 1) {
if (!/^(?:CA\$|\$)\s*\d+/.test(lines[i])) continue;
const title = lines[i - 1];
if (!title || /^(Hide|All listings|Needs attention|Marketplace|Selling)$/i.test(title)) continue;View on GitHub (pinned to 49907e53dc)
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
Defensive patterns
Strategy: validation
Validate before calling
if (!page || typeof page.goto !== 'function') {
throw new Error('Browser session required: launch the managed Chrome profile before running marketplace-listings');
} Type guard
const hasPage = (p) => !!p && typeof p.goto === 'function' && typeof p.evaluate === 'function';
Try / catch
try {
await runMarketplaceListings();
} catch (e) {
if (/Browser session required/.test(e.message)) {
await launchManagedBrowser(); // then retry
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Browser session required for facebook marketplace-inbox
- 12306 whoami failed: ${probe.detail}
- Browser session required for bilibili comment
- Browser session required for bilibili summary
- Browser session required for instagram note
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/c865a3797515236c.
Report an issue: GitHub.