Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/__tests__/commands/crawl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,50 @@ describe('executeCrawl', () => {
}
);
});

it('should include scrapeOptions.maxAge when provided', async () => {
const mockResponse = {
id: '550e8400-e29b-41d4-a716-446655440000',
url: 'https://example.com',
};
mockClient.startCrawl.mockResolvedValue(mockResponse);

await executeCrawl({
urlOrJobId: 'https://example.com',
maxAge: 172800000,
});

expect(mockClient.startCrawl).toHaveBeenCalledWith(
'https://example.com',
{
scrapeOptions: {
maxAge: 172800000,
},
}
);
});

it('should include scrapeOptions.onlyMainContent when provided', async () => {
const mockResponse = {
id: '550e8400-e29b-41d4-a716-446655440000',
url: 'https://example.com',
};
mockClient.startCrawl.mockResolvedValue(mockResponse);

await executeCrawl({
urlOrJobId: 'https://example.com',
onlyMainContent: true,
});

expect(mockClient.startCrawl).toHaveBeenCalledWith(
'https://example.com',
{
scrapeOptions: {
onlyMainContent: true,
},
}
);
});
});

describe('Check crawl status', () => {
Expand Down
12 changes: 12 additions & 0 deletions src/commands/crawl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ export async function executeCrawl(
if (options.maxConcurrency !== undefined) {
crawlOptions.maxConcurrency = options.maxConcurrency;
}
if (options.maxAge !== undefined) {
crawlOptions.scrapeOptions = {
...(crawlOptions.scrapeOptions ?? {}),
maxAge: options.maxAge,
};
}
if (options.onlyMainContent !== undefined) {
crawlOptions.scrapeOptions = {
...(crawlOptions.scrapeOptions ?? {}),
onlyMainContent: options.onlyMainContent,
};
}

// If wait mode, use the convenience crawl method with polling
if (wait) {
Expand Down
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ function createCrawlCommand(): Command {
'Maximum concurrent requests',
parseInt
)
.option(
'--max-age <milliseconds>',
'Maximum age of cached content in milliseconds',
parseInt
)
.option('--only-main-content', 'Include only main content', false)
.option(
'-k, --api-key <key>',
'Firecrawl API key (overrides global --api-key)'
Expand Down Expand Up @@ -260,6 +266,8 @@ function createCrawlCommand(): Command {
allowSubdomains: options.allowSubdomains,
delay: options.delay,
maxConcurrency: options.maxConcurrency,
maxAge: options.maxAge,
onlyMainContent: options.onlyMainContent,
};

await handleCrawlCommand(crawlOptions);
Expand Down
4 changes: 4 additions & 0 deletions src/types/crawl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export interface CrawlOptions {
delay?: number;
/** Maximum concurrency */
maxConcurrency?: number;
/** Maximum age of cached content in milliseconds (API-level caching) */
maxAge?: number;
/** Include only main content */
onlyMainContent?: boolean;
}

export interface CrawlResult {
Expand Down