Skip to content

Commit 1fe2280

Browse files
authored
Merge pull request #6 from ScrapeGraphAI/feat/add-wait-ms-to-crawl
feat: add wait_ms parameter to crawl endpoint
2 parents 56285f8 + acbc781 commit 1fe2280

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/crawl.js

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

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

114+
if (waitMs !== null) {
115+
if (!Number.isInteger(waitMs) || waitMs < 0) {
116+
throw new Error('waitMs must be a positive integer');
117+
}
118+
payload.wait_ms = waitMs;
119+
}
120+
113121
try {
114122
const response = await axios.post(endpoint, payload, { headers });
115123
return response.data;

0 commit comments

Comments
 (0)