diff --git a/package.json b/package.json index 026c386..2f0dc5f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "firecrawl-cli", - "version": "1.9.1", + "version": "1.9.2", "description": "Command-line interface for Firecrawl. Scrape, crawl, and extract data from any website directly from your terminal.", "main": "dist/index.js", "bin": { diff --git a/src/__tests__/commands/browser.test.ts b/src/__tests__/commands/browser.test.ts index b0daaec..e45942f 100644 --- a/src/__tests__/commands/browser.test.ts +++ b/src/__tests__/commands/browser.test.ts @@ -69,6 +69,44 @@ describe('Browser Commands', () => { vi.clearAllMocks(); }); + it('launch passes origin cli to browser()', async () => { + mockClient.browser.mockResolvedValue({ + success: true, + id: 'session-123', + cdpUrl: 'wss://cdp.example.com/session-123', + }); + + await handleBrowserLaunch({}); + + expect(mockClient.browser).toHaveBeenCalledWith( + expect.objectContaining({ origin: 'cli' }) + ); + }); + + it('launch passes origin cli alongside other options', async () => { + mockClient.browser.mockResolvedValue({ + success: true, + id: 'session-123', + cdpUrl: 'wss://cdp.example.com/session-123', + }); + + await handleBrowserLaunch({ + ttl: 600, + ttlInactivity: 120, + profile: 'my-profile', + saveChanges: true, + }); + + expect(mockClient.browser).toHaveBeenCalledWith( + expect.objectContaining({ + origin: 'cli', + ttl: 600, + activityTtl: 120, + profile: { name: 'my-profile', saveChanges: true }, + }) + ); + }); + it('launch saves session on success', async () => { mockClient.browser.mockResolvedValue({ success: true, @@ -159,11 +197,43 @@ describe('Browser Commands', () => { await handleBrowserQuickExecute({ code: 'open https://example.com' }); expect(mockClient.browser).toHaveBeenCalledTimes(1); + expect(mockClient.browser).toHaveBeenCalledWith( + expect.objectContaining({ origin: 'cli' }) + ); expect(saveBrowserSession).toHaveBeenCalledWith( expect.objectContaining({ id: 'new-session' }) ); }); + it('quick execute auto-launch passes origin cli with profile', async () => { + const { loadBrowserSession } = await import('../../utils/browser-session'); + vi.mocked(loadBrowserSession).mockReturnValueOnce(null); + vi.mocked(loadBrowserSession).mockReturnValue({ + id: 'new-session', + cdpUrl: 'wss://new', + createdAt: '2025-01-01T00:00:00Z', + }); + + mockClient.browser.mockResolvedValue({ + success: true, + id: 'new-session', + cdpUrl: 'wss://new', + }); + + await handleBrowserQuickExecute({ + code: 'open https://example.com', + profile: 'dev', + saveChanges: false, + }); + + expect(mockClient.browser).toHaveBeenCalledWith( + expect.objectContaining({ + origin: 'cli', + profile: { name: 'dev', saveChanges: false }, + }) + ); + }); + it('quick execute retries with new session on 403 Forbidden', async () => { const { clearBrowserSession, saveBrowserSession } = await import('../../utils/browser-session'); diff --git a/src/__tests__/commands/crawl.test.ts b/src/__tests__/commands/crawl.test.ts index 956bc1a..5d57895 100644 --- a/src/__tests__/commands/crawl.test.ts +++ b/src/__tests__/commands/crawl.test.ts @@ -59,7 +59,7 @@ describe('executeCrawl', () => { expect(mockClient.startCrawl).toHaveBeenCalledTimes(1); expect(mockClient.startCrawl).toHaveBeenCalledWith( 'https://example.com', - {} + { origin: 'cli' } ); expect(result).toEqual({ success: true, @@ -233,6 +233,7 @@ describe('executeCrawl', () => { expect(mockClient.startCrawl).toHaveBeenCalledWith( 'https://example.com', { + origin: 'cli', limit: 50, maxDiscoveryDepth: 2, excludePaths: ['/admin'], diff --git a/src/__tests__/commands/map.test.ts b/src/__tests__/commands/map.test.ts index 9b111b4..99b71b0 100644 --- a/src/__tests__/commands/map.test.ts +++ b/src/__tests__/commands/map.test.ts @@ -57,7 +57,9 @@ describe('executeMap', () => { }); expect(mockClient.map).toHaveBeenCalledTimes(1); - expect(mockClient.map).toHaveBeenCalledWith('https://example.com', {}); + expect(mockClient.map).toHaveBeenCalledWith('https://example.com', { + origin: 'cli', + }); }); it('should pass apiUrl to getClient when provided', async () => { @@ -229,6 +231,7 @@ describe('executeMap', () => { }); expect(mockClient.map).toHaveBeenCalledWith('https://example.com', { + origin: 'cli', limit: 100, search: 'blog', sitemap: 'include', diff --git a/src/__tests__/commands/scrape.test.ts b/src/__tests__/commands/scrape.test.ts index fdf98c7..2381cd7 100644 --- a/src/__tests__/commands/scrape.test.ts +++ b/src/__tests__/commands/scrape.test.ts @@ -54,6 +54,7 @@ describe('executeScrape', () => { expect(mockClient.scrape).toHaveBeenCalledTimes(1); expect(mockClient.scrape).toHaveBeenCalledWith('https://example.com', { formats: ['markdown'], + origin: 'cli', }); }); @@ -99,6 +100,7 @@ describe('executeScrape', () => { expect(mockClient.scrape).toHaveBeenCalledWith('https://example.com', { formats: ['html'], + origin: 'cli', }); }); @@ -113,6 +115,7 @@ describe('executeScrape', () => { expect(mockClient.scrape).toHaveBeenCalledWith('https://example.com', { formats: ['summary'], + origin: 'cli', }); }); @@ -130,6 +133,7 @@ describe('executeScrape', () => { expect(mockClient.scrape).toHaveBeenCalledWith('https://example.com', { formats: ['screenshot'], + origin: 'cli', }); }); @@ -148,6 +152,7 @@ describe('executeScrape', () => { expect(mockClient.scrape).toHaveBeenCalledWith('https://example.com', { formats: ['markdown', 'screenshot'], + origin: 'cli', }); }); @@ -162,6 +167,7 @@ describe('executeScrape', () => { expect(mockClient.scrape).toHaveBeenCalledWith('https://example.com', { formats: ['markdown'], + origin: 'cli', onlyMainContent: true, }); }); @@ -177,6 +183,7 @@ describe('executeScrape', () => { expect(mockClient.scrape).toHaveBeenCalledWith('https://example.com', { formats: ['markdown'], + origin: 'cli', waitFor: 2000, }); }); @@ -192,6 +199,7 @@ describe('executeScrape', () => { expect(mockClient.scrape).toHaveBeenCalledWith('https://example.com', { formats: ['markdown'], + origin: 'cli', includeTags: ['article', 'main'], }); }); @@ -207,6 +215,7 @@ describe('executeScrape', () => { expect(mockClient.scrape).toHaveBeenCalledWith('https://example.com', { formats: ['markdown'], + origin: 'cli', excludeTags: ['nav', 'footer'], }); }); @@ -227,6 +236,7 @@ describe('executeScrape', () => { expect(mockClient.scrape).toHaveBeenCalledWith('https://example.com', { formats: ['markdown', 'screenshot'], + origin: 'cli', onlyMainContent: true, waitFor: 3000, includeTags: ['article'], @@ -245,6 +255,7 @@ describe('executeScrape', () => { expect(mockClient.scrape).toHaveBeenCalledWith('https://example.com', { formats: ['markdown'], + origin: 'cli', maxAge: 3600, }); }); @@ -260,6 +271,7 @@ describe('executeScrape', () => { expect(mockClient.scrape).toHaveBeenCalledWith('https://example.com', { formats: ['markdown'], + origin: 'cli', location: { country: 'US', languages: ['en'] }, }); }); @@ -275,6 +287,7 @@ describe('executeScrape', () => { expect(mockClient.scrape).toHaveBeenCalledWith('https://example.com', { formats: ['markdown'], + origin: 'cli', location: { country: 'DE' }, }); }); @@ -290,6 +303,7 @@ describe('executeScrape', () => { expect(mockClient.scrape).toHaveBeenCalledWith('https://example.com', { formats: ['markdown'], + origin: 'cli', location: { languages: ['en', 'es'] }, }); }); @@ -304,6 +318,7 @@ describe('executeScrape', () => { expect(mockClient.scrape).toHaveBeenCalledWith('https://example.com', { formats: ['markdown'], + origin: 'cli', }); }); }); @@ -406,6 +421,7 @@ describe('executeScrape', () => { expect(result.success).toBe(true); expect(mockClient.scrape).toHaveBeenCalledWith('https://example.com', { formats: ['markdown', 'links', 'images'], + origin: 'cli', }); }); }); diff --git a/src/__tests__/commands/search.test.ts b/src/__tests__/commands/search.test.ts index 012715e..cb12028 100644 --- a/src/__tests__/commands/search.test.ts +++ b/src/__tests__/commands/search.test.ts @@ -58,6 +58,7 @@ describe('executeSearch', () => { expect(mockClient.search).toHaveBeenCalledTimes(1); expect(mockClient.search).toHaveBeenCalledWith('test query', { limit: undefined, + origin: 'cli', }); }); @@ -351,6 +352,7 @@ describe('executeSearch', () => { expect(mockClient.search).toHaveBeenCalledWith('comprehensive test', { limit: 20, + origin: 'cli', sources: [{ type: 'web' }, { type: 'news' }], categories: [{ type: 'github' }], tbs: 'qdr:w', diff --git a/src/commands/agent.ts b/src/commands/agent.ts index e6e5217..63332f5 100644 --- a/src/commands/agent.ts +++ b/src/commands/agent.ts @@ -201,8 +201,10 @@ export async function executeAgent( maxCredits?: number; pollInterval?: number; timeout?: number; + origin?: string; } = { prompt, + origin: 'cli', }; if (options.urls && options.urls.length > 0) { diff --git a/src/commands/browser.ts b/src/commands/browser.ts index 3e4cf21..9bca940 100644 --- a/src/commands/browser.ts +++ b/src/commands/browser.ts @@ -76,7 +76,8 @@ export async function handleBrowserLaunch( name: string; saveChanges?: boolean; }; - } = {}; + origin?: string; + } = { origin: 'cli' }; if (options.ttl !== undefined) args.ttl = options.ttl; if (options.ttlInactivity !== undefined) args.activityTtl = options.ttlInactivity; @@ -290,7 +291,8 @@ export async function handleBrowserQuickExecute( name: string; saveChanges?: boolean; }; - } = {}; + origin?: string; + } = { origin: 'cli' }; if (options.profile) { launchArgs.profile = { name: options.profile, diff --git a/src/commands/crawl.ts b/src/commands/crawl.ts index 54daaf6..cb8d0f3 100644 --- a/src/commands/crawl.ts +++ b/src/commands/crawl.ts @@ -57,7 +57,9 @@ export async function executeCrawl( } // Build crawl options - const crawlOptions: any = {}; + const crawlOptions: any = { + origin: 'cli', + }; if (options.limit !== undefined) { crawlOptions.limit = options.limit; diff --git a/src/commands/map.ts b/src/commands/map.ts index 301e12d..5f97fd9 100644 --- a/src/commands/map.ts +++ b/src/commands/map.ts @@ -15,7 +15,9 @@ export async function executeMap(options: MapOptions): Promise { const { urlOrJobId } = options; // Build map options - const mapOptions: any = {}; + const mapOptions: any = { + origin: 'cli', + }; if (options.limit !== undefined) { mapOptions.limit = options.limit; diff --git a/src/commands/scrape.ts b/src/commands/scrape.ts index a106053..c9011d3 100644 --- a/src/commands/scrape.ts +++ b/src/commands/scrape.ts @@ -76,16 +76,9 @@ export async function executeScrape( formats.push('markdown'); } - const scrapeParams: { - formats?: FormatOption[]; - onlyMainContent?: boolean; - waitFor?: number; - includeTags?: string[]; - excludeTags?: string[]; - maxAge?: number; - location?: ScrapeLocation; - } = { + const scrapeParams: Record = { formats, + origin: 'cli', }; if (options.onlyMainContent !== undefined) { diff --git a/src/commands/search.ts b/src/commands/search.ts index f2fd5d2..15a3471 100644 --- a/src/commands/search.ts +++ b/src/commands/search.ts @@ -26,6 +26,7 @@ export async function executeSearch( // Build search options for the SDK const searchParams: Record = { limit: options.limit, + origin: 'cli', }; // Add sources if specified