Skip to content
Merged
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
10 changes: 9 additions & 1 deletion src/crawl.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { getMockResponse } from './utils/mockResponse.js';
* @param {Array<string>} [options.includePaths] - List of path patterns to include (e.g., ['/products/*', '/blog/**']). Supports wildcards: * matches any characters, ** matches any path segments
* @param {Array<string>} [options.excludePaths] - List of path patterns to exclude (e.g., ['/admin/*', '/api/*']). Supports wildcards and takes precedence over includePaths
* @param {string} [options.webhookUrl] - URL to receive webhook notifications when the crawl job completes
* @param {number|null} [options.waitMs] - Time in milliseconds to wait for JavaScript rendering (default 3000 on server)
* @returns {Promise<Object>} The crawl job response
* @throws {Error} Throws an error if the HTTP request fails
*/
Expand All @@ -37,7 +38,7 @@ export async function crawl(
schema,
options = {}
) {
const { mock = null, renderHeavyJs = false, stealth = false, includePaths = null, excludePaths = null, webhookUrl = null, extractionMode = true } = options;
const { mock = null, renderHeavyJs = false, stealth = false, includePaths = null, excludePaths = null, webhookUrl = null, extractionMode = true, waitMs = null } = options;

// Check if mock mode is enabled
const useMock = mock !== null ? mock : isMockEnabled();
Expand Down Expand Up @@ -110,6 +111,13 @@ export async function crawl(
payload.webhook_url = webhookUrl;
}

if (waitMs !== null) {
if (!Number.isInteger(waitMs) || waitMs < 0) {
throw new Error('waitMs must be a positive integer');
}
payload.wait_ms = waitMs;
}

try {
const response = await axios.post(endpoint, payload, { headers });
return response.data;
Expand Down