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.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
fix(core): ignore explicitly undefined baseUrl in enqueueLinks helpers (#3924)
Martin Adámeka58a9c1417c3
diff --git a/packages/browser-crawler/src/internals/browser-crawler.ts b/packages/browser-crawler/src/internals/browser-crawler.tsindex b61503a57..a8fae22a8 100644--- a/packages/browser-crawler/src/internals/browser-crawler.ts+++ b/packages/browser-crawler/src/internals/browser-crawler.ts@@ -859,8 +859,8 @@ export async function browserCrawlerEnqueueLinks(if (containsEnqueueLinks(options)) {return options.enqueueLinks({urls,- baseUrl,...enqueueLinksOptions,+ baseUrl,});}return enqueueLinks({@@ -868,8 +868,8 @@ export async function browserCrawlerEnqueueLinks(robotsTxtFile: options.robotsTxtFile,onSkippedRequest: options.onSkippedRequest,urls,- baseUrl,...(enqueueLinksOptions as EnqueueLinksOptions),+ baseUrl,});}diff --git a/packages/cheerio-crawler/src/internals/cheerio-crawler.ts b/packages/cheerio-crawler/src/internals/cheerio-crawler.tsindex 2f00e7db2..3abab1167 100644--- a/packages/cheerio-crawler/src/internals/cheerio-crawler.ts+++ b/packages/cheerio-crawler/src/internals/cheerio-crawler.ts@@ -294,8 +294,8 @@ export async function cheerioCrawlerEnqueueLinks(if (containsEnqueueLinks(options)) {return options.enqueueLinks({urls,- baseUrl,...enqueueLinksOptions,+ baseUrl,});}return enqueueLinks({@@ -303,8 +303,8 @@ export async function cheerioCrawlerEnqueueLinks(robotsTxtFile: options.robotsTxtFile,onSkippedRequest: options.onSkippedRequest,urls,- baseUrl,...enqueueLinksOptions,+ baseUrl,});}diff --git a/packages/jsdom-crawler/src/internals/jsdom-crawler.ts b/packages/jsdom-crawler/src/internals/jsdom-crawler.tsindex e26d134dc..627c0ce72 100644--- a/packages/jsdom-crawler/src/internals/jsdom-crawler.ts+++ b/packages/jsdom-crawler/src/internals/jsdom-crawler.ts@@ -395,8 +395,8 @@ export async function domCrawlerEnqueueLinks(options: EnqueueLinksInternalOptionif (containsEnqueueLinks(options)) {return options.enqueueLinks({urls,- baseUrl,...enqueueLinksOptions,+ baseUrl,});}@@ -405,8 +405,8 @@ export async function domCrawlerEnqueueLinks(options: EnqueueLinksInternalOptionrobotsTxtFile: options.robotsTxtFile,onSkippedRequest: options.onSkippedRequest,urls,- baseUrl,...enqueueLinksOptions,+ baseUrl,});}diff --git a/packages/linkedom-crawler/src/internals/linkedom-crawler.ts b/packages/linkedom-crawler/src/internals/linkedom-crawler.tsindex e09d66afb..fbc2bc1e9 100644--- a/packages/linkedom-crawler/src/internals/linkedom-crawler.ts+++ b/packages/linkedom-crawler/src/internals/linkedom-crawler.ts@@ -280,8 +280,8 @@ export async function linkedomCrawlerEnqueueLinks(if (containsEnqueueLinks(options)) {return options.enqueueLinks({urls,- baseUrl,...enqueueLinksOptions,+ baseUrl,});}@@ -290,8 +290,8 @@ export async function linkedomCrawlerEnqueueLinks(robotsTxtFile: options.robotsTxtFile,onSkippedRequest: options.onSkippedRequest,urls,- baseUrl,...enqueueLinksOptions,+ baseUrl,});}diff --git a/test/core/enqueue_links/enqueue_links.test.ts b/test/core/enqueue_links/enqueue_links.test.tsindex a4231d7e4..820b20f0d 100644--- a/test/core/enqueue_links/enqueue_links.test.ts+++ b/test/core/enqueue_links/enqueue_links.test.ts@@ -911,6 +911,40 @@ describe('enqueueLinks()', () => {expect(enqueued[2].userData).toEqual({});});+ test('ignores an explicitly undefined baseUrl and keeps the resolved one', async () => {+ const { enqueued, requestQueue } = createRequestQueueMock();+ await cheerioCrawlerEnqueueLinks({+ options: { strategy: EnqueueStrategy.SameDomain, baseUrl: undefined },+ $,+ requestQueue,+ originalRequestUrl: 'https://example.com',+ });++ expect(enqueued.map((request) => request.url)).toEqual([+ 'https://example.com/a/b/first',+ 'https://example.com/a/second',+ 'https://example.com/a/b/third',+ 'https://example.com/x/absolutepath',+ 'https://example.com/y/relativepath',+ ]);+ });++ test('ignores an explicitly undefined baseUrl when delegating to the bound enqueueLinks', async () => {+ let forwardedBaseUrl: string | undefined;++ await cheerioCrawlerEnqueueLinks({+ options: { strategy: EnqueueStrategy.SameDomain, baseUrl: undefined },+ $,+ originalRequestUrl: 'https://example.com',+ enqueueLinks: async (options) => {+ forwardedBaseUrl = options?.baseUrl;+ return { processedRequests: [], unprocessedRequests: [] };+ },+ });++ expect(forwardedBaseUrl).toBe('https://example.com');+ });+test('keeps filtering by the original domain with the strategy of same-domain after an off-domain redirect', async () => {const { enqueued, requestQueue } = createRequestQueueMock();await cheerioCrawlerEnqueueLinks({