@crawlee/playwright 4.0.0-beta.122 → 4.0.0-beta.123

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -190,6 +190,7 @@ export declare class AdaptivePlaywrightCrawler<ContextExtension = Dictionary<nev
190
190
  readonly querySelectorAll: AdaptivePlaywrightCrawlerContext["querySelectorAll"];
191
191
  readonly waitForSelector: AdaptivePlaywrightCrawlerContext["waitForSelector"];
192
192
  readonly parseWithCheerio: AdaptivePlaywrightCrawlerContext["parseWithCheerio"];
193
+ readonly enqueueLinks: AdaptivePlaywrightCrawlerContext["enqueueLinks"];
193
194
  }>;
194
195
  private adaptCheerioContext;
195
196
  private adaptPlaywrightContext;
@@ -2,7 +2,7 @@ import { isDeepStrictEqual } from 'node:util';
2
2
  import { BasicCrawler } from '@crawlee/basic';
3
3
  import { extractUrlsFromPage } from '@crawlee/browser';
4
4
  import { CheerioCrawler } from '@crawlee/cheerio';
5
- import { createStorageTransaction, OwnedOrInjected, parseArgument, RequestHandlerError, resolveBaseUrlForEnqueueLinksFiltering, Router, Statistics, } from '@crawlee/core';
5
+ import { createStorageTransaction, EnqueueStrategy, OwnedOrInjected, parseArgument, RequestHandlerError, resolveBaseUrlForEnqueueLinksFiltering, Router, Statistics, } from '@crawlee/core';
6
6
  import { extractUrlsFromCheerio } from '@crawlee/utils/internal';
7
7
  import { z } from 'zod';
8
8
  import { addTimeoutToPromise } from '@apify/timeout';
@@ -218,6 +218,9 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
218
218
  get parseWithCheerio() {
219
219
  throw new Error(errorMessage('parseWithCheerio'));
220
220
  },
221
+ get enqueueLinks() {
222
+ throw new Error(errorMessage('enqueueLinks'));
223
+ },
221
224
  }),
222
225
  });
223
226
  }
@@ -233,9 +236,8 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
233
236
  return cheerioContext.$(selector);
234
237
  },
235
238
  enqueueLinks: async (options = {}) => {
236
- const urls = options.urls ??
237
- extractUrlsFromCheerio(cheerioContext.$, options.selector, options.baseUrl ?? cheerioContext.request.loadedUrl);
238
- return (await this.enqueueLinks({ ...options, urls }, cheerioContext.request));
239
+ const urls = extractUrlsFromCheerio(cheerioContext.$, options.selector, options.baseUrl ?? cheerioContext.request.loadedUrl);
240
+ return (await this.enqueueLinks(urls, options, cheerioContext.request));
239
241
  },
240
242
  response: cheerioContext.response,
241
243
  };
@@ -263,19 +265,11 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
263
265
  },
264
266
  enqueueLinks: async (options = {}, timeoutMs = 5000) => {
265
267
  // TODO consider using `context.parseWithCheerio` to make this universal and avoid code duplication
266
- let urls;
267
- if (options.urls === undefined) {
268
- const selector = options.selector ?? 'a';
269
- const locator = playwrightContext.page.locator(selector).first();
270
- await locator.waitFor({ timeout: timeoutMs, state: 'attached' });
271
- urls =
272
- options.urls ??
273
- (await extractUrlsFromPage(playwrightContext.page, selector, options.baseUrl ?? playwrightContext.request.loadedUrl));
274
- }
275
- else {
276
- urls = options.urls;
277
- }
278
- return (await this.enqueueLinks({ ...options, urls }, playwrightContext.request));
268
+ const selector = options.selector ?? 'a';
269
+ const locator = playwrightContext.page.locator(selector).first();
270
+ await locator.waitFor({ timeout: timeoutMs, state: 'attached' });
271
+ const urls = await extractUrlsFromPage(playwrightContext.page, selector, options.baseUrl ?? playwrightContext.request.loadedUrl);
272
+ return (await this.enqueueLinks(urls, options, playwrightContext.request));
279
273
  },
280
274
  };
281
275
  }
@@ -423,16 +417,21 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
423
417
  }
424
418
  }
425
419
  }
426
- async enqueueLinks(options, request) {
420
+ async enqueueLinks(urls, options, request) {
427
421
  const baseUrl = resolveBaseUrlForEnqueueLinksFiltering({
428
422
  enqueueStrategy: options?.strategy,
429
423
  finalRequestUrl: request.loadedUrl,
430
424
  originalRequestUrl: request.url,
431
425
  userProvidedBaseUrl: options?.baseUrl,
432
426
  });
427
+ const requestsWithDepth = this.addCrawlDepthRequestGenerator(urls, request.crawlDepth + 1);
433
428
  // The per-attempt transaction buffers these (the queue policy defaults to `deferred` here),
434
429
  // so a discarded attempt's enqueues never reach the queue.
435
- return await this.enqueueLinksWithCrawlDepth({ ...options, baseUrl }, request, await this.getRequestManager());
430
+ return await this.addRequests(requestsWithDepth, {
431
+ ...options,
432
+ baseUrl,
433
+ strategy: options.strategy ?? EnqueueStrategy.SameHostname,
434
+ });
436
435
  }
437
436
  createLogProxy(log, logs) {
438
437
  return new Proxy(log, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/playwright",
3
- "version": "4.0.0-beta.122",
3
+ "version": "4.0.0-beta.123",
4
4
  "description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"
@@ -49,13 +49,13 @@
49
49
  "dependencies": {
50
50
  "@apify/datastructures": "^2.0.3",
51
51
  "@apify/timeout": "^0.4.4",
52
- "@crawlee/basic": "4.0.0-beta.122",
53
- "@crawlee/browser": "4.0.0-beta.122",
54
- "@crawlee/browser-pool": "4.0.0-beta.122",
55
- "@crawlee/cheerio": "4.0.0-beta.122",
56
- "@crawlee/core": "4.0.0-beta.122",
57
- "@crawlee/types": "4.0.0-beta.122",
58
- "@crawlee/utils": "4.0.0-beta.122",
52
+ "@crawlee/basic": "4.0.0-beta.123",
53
+ "@crawlee/browser": "4.0.0-beta.123",
54
+ "@crawlee/browser-pool": "4.0.0-beta.123",
55
+ "@crawlee/cheerio": "4.0.0-beta.123",
56
+ "@crawlee/core": "4.0.0-beta.123",
57
+ "@crawlee/types": "4.0.0-beta.123",
58
+ "@crawlee/utils": "4.0.0-beta.123",
59
59
  "cheerio": "^1.0.0",
60
60
  "jquery": "^3.7.1",
61
61
  "ml-logistic-regression": "^2.0.0",
@@ -84,5 +84,5 @@
84
84
  }
85
85
  }
86
86
  },
87
- "gitHead": "2c3e87fefdb9e1fca4c144f03167d8524cfdc2e5"
87
+ "gitHead": "f77648095c6a3f5ed8815c7620ea765db430ae44"
88
88
  }