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.

fix(jsdom): use no-op `enqueueLinks` in http crawlers when parsing fails

Martin Adámekfd35270e7da6
diff --git a/packages/http-crawler/src/internals/http-crawler.ts b/packages/http-crawler/src/internals/http-crawler.ts
index 227132f3a..bac6dbb13 100644
--- a/packages/http-crawler/src/internals/http-crawler.ts
+++ b/packages/http-crawler/src/internals/http-crawler.ts
@@ -609,7 +609,7 @@ export class HttpCrawler<Context extends InternalHttpCrawlingContext<any, any, H
return { ...parsed, isXml, response, contentType };
} else {
const body = await concatStreamToBuffer(response);
- return { body, response, contentType };
+ return { body, response, contentType, enqueueLinks: () => Promise.resolve({ processedRequests: [], unprocessedRequests: [] }) };
}
}
diff --git a/packages/jsdom-crawler/src/internals/jsdom-crawler.ts b/packages/jsdom-crawler/src/internals/jsdom-crawler.ts
index 30d75a1d4..9a4ed0cbc 100644
--- a/packages/jsdom-crawler/src/internals/jsdom-crawler.ts
+++ b/packages/jsdom-crawler/src/internals/jsdom-crawler.ts
@@ -285,7 +285,7 @@ export async function domCrawlerEnqueueLinks({ options, window, requestQueue, or
userProvidedBaseUrl: options?.baseUrl,
});
- const urls = extractUrlsFromWindow(window, options?.selector ?? 'a', options?.baseUrl ?? finalRequestUrl ?? originalRequestUrl) ?? [];
+ const urls = extractUrlsFromWindow(window, options?.selector ?? 'a', options?.baseUrl ?? finalRequestUrl ?? originalRequestUrl);
return enqueueLinks({
requestQueue,