Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

feat(core): add `forefront` option to `enqueueLinks` helper

Martin Adámekf8755b633212
diff --git a/packages/core/src/enqueue_links/enqueue_links.ts b/packages/core/src/enqueue_links/enqueue_links.ts
index 25a0eb65f..13e1ffff1 100644
--- a/packages/core/src/enqueue_links/enqueue_links.ts
+++ b/packages/core/src/enqueue_links/enqueue_links.ts
@@ -12,10 +12,10 @@ import {
createRequestOptions,
createRequests,
} from './shared';
-import type { RequestQueue } from '../storages/request_queue';
+import type { RequestQueue, RequestQueueOperationOptions } from '../storages/request_queue';
import type { RequestOptions } from '../request';
-export interface EnqueueLinksOptions {
+export interface EnqueueLinksOptions extends RequestQueueOperationOptions {
/** Limit the amount of actually enqueued URLs to this number. Useful for testing across the entire crawling scope. */
limit?: number;
@@ -169,6 +169,7 @@ export async function enqueueLinks(options: SetRequired<EnqueueLinksOptions, 're
ow(options, ow.object.exactShape({
urls: ow.array.ofType(ow.string),
requestQueue: ow.object.hasKeys('fetchNextRequest', 'addRequest'),
+ forefront: ow.optional.boolean,
limit: ow.optional.number,
selector: ow.optional.string,
baseUrl: ow.optional.string,
@@ -202,6 +203,7 @@ export async function enqueueLinks(options: SetRequired<EnqueueLinksOptions, 're
globs,
regexps,
transformRequestFunction,
+ forefront,
} = options;
const urlPatternObjects: UrlPatternObject[] = [];
@@ -281,7 +283,7 @@ export async function enqueueLinks(options: SetRequired<EnqueueLinksOptions, 're
let requests = createFilteredRequests();
if (limit) requests = requests.slice(0, limit);
- return requestQueue.addRequests(requests);
+ return requestQueue.addRequests(requests, { forefront });
}
/**