@crawlee/playwright 4.0.0-beta.232 → 4.0.0-beta.235

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.
@@ -184,8 +184,6 @@ export interface AdaptivePlaywrightCrawlerOptions<ContextExtension = Dictionary<
184
184
  * 'http://www.example.com/page-2',
185
185
  * ]);
186
186
  * ```
187
- *
188
- * @experimental
189
187
  */
190
188
  export declare class AdaptivePlaywrightCrawler<ContextExtension = Dictionary<never>, ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<AdaptivePlaywrightCrawlerContext['request']>>, StatisticStateExtension extends AdaptivePlaywrightCrawlerStatisticState = AdaptivePlaywrightCrawlerStatisticState> extends BasicCrawler<AdaptivePlaywrightCrawlerContext, ContextExtension, ExtendedContext, Routes, StatisticStateExtension> {
191
189
  #private;
@@ -3,6 +3,7 @@ import { isDeepStrictEqual } from 'node:util';
3
3
  import { BasicCrawler, ContextPipeline, ContextPipelineInitializationError, ContextPipelineInterruptedError, RequestHandlerError, resolveBaseUrlForEnqueueLinksFiltering, Router, Statistics, } from '@crawlee/basic';
4
4
  import { extractUrlsFromPage } from '@crawlee/browser';
5
5
  import { CheerioCrawler } from '@crawlee/cheerio';
6
+ import { ResponseWithUrl } from '@crawlee/http-client';
6
7
  import { createStorageTransaction, EnqueueStrategy, OwnedOrInjected } from '@crawlee/core';
7
8
  import { extractUrlsFromCheerio, parseArgument } from '@crawlee/utils/internal';
8
9
  import { z } from 'zod';
@@ -61,8 +62,6 @@ const proxyLogMethods = [
61
62
  * 'http://www.example.com/page-2',
62
63
  * ]);
63
64
  * ```
64
- *
65
- * @experimental
66
65
  */
67
66
  export class AdaptivePlaywrightCrawler extends BasicCrawler {
68
67
  #renderingTypePredictor;
@@ -234,23 +233,30 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
234
233
  const urls = extractUrlsFromCheerio(cheerioContext.$, options.selector, options.baseUrl ?? cheerioContext.request.loadedUrl);
235
234
  return (await this.#enqueueLinks(urls, options, cheerioContext.request));
236
235
  },
237
- response: cheerioContext.response,
236
+ // The HTTP crawler has already consumed the body; hand out a fresh copy, like the browser side does.
237
+ // HTML bodies are already decoded to UTF-8, so `arrayBuffer()` may disagree with the original headers.
238
+ response: new ResponseWithUrl(cheerioContext.body, cheerioContext.response),
238
239
  };
239
240
  }
240
241
  async #adaptPlaywrightContext(playwrightContext) {
241
242
  // Capture the original response to avoid infinite recursion when the getter is copied to the context
242
243
  const originalResponse = playwrightContext.response;
243
244
  return {
244
- response: new Response(Uint8Array.from(await originalResponse.body()), {
245
+ response: new ResponseWithUrl(Uint8Array.from(await originalResponse.body()), {
245
246
  headers: originalResponse.headers(),
246
247
  status: originalResponse.status(),
247
248
  statusText: originalResponse.statusText(),
249
+ url: originalResponse.url(),
248
250
  }),
249
251
  enqueueLinks: async (options = {}, timeoutMs = 5000) => {
250
252
  // TODO consider using `context.parseWithCheerio` to make this universal and avoid code duplication
251
253
  const selector = options.selector ?? 'a';
252
254
  const locator = playwrightContext.page.locator(selector).first();
253
- await locator.waitFor({ timeout: timeoutMs, state: 'attached' });
255
+ // Wait for client-rendered links, but like the HTTP side, enqueue nothing when there are none.
256
+ await locator.waitFor({ timeout: timeoutMs, state: 'attached' }).catch((error) => {
257
+ if (error.name !== 'TimeoutError')
258
+ throw error;
259
+ });
254
260
  const urls = await extractUrlsFromPage(playwrightContext.page, selector, options.baseUrl ?? playwrightContext.request.loadedUrl);
255
261
  return (await this.#enqueueLinks(urls, options, playwrightContext.request));
256
262
  },
@@ -9,8 +9,6 @@ export interface RenderingTypePredictorOptions {
9
9
  /**
10
10
  * Minimal contract that any object passed to {@link AdaptivePlaywrightCrawler} as its
11
11
  * `renderingTypePredictor` option must satisfy.
12
- *
13
- * @experimental
14
12
  */
15
13
  export interface IRenderingTypePredictor {
16
14
  /**
@@ -35,8 +33,6 @@ export interface IRenderingTypePredictor {
35
33
  }
36
34
  /**
37
35
  * Stores rendering type information for previously crawled URLs and predicts the rendering type for URLs that have yet to be crawled and recommends when rendering type detection should be performed.
38
- *
39
- * @experimental
40
36
  */
41
37
  export declare class RenderingTypePredictor implements IRenderingTypePredictor {
42
38
  #private;
@@ -62,8 +62,6 @@ const stateCodec = z.codec(persistedState, predictorState, {
62
62
  });
63
63
  /**
64
64
  * Stores rendering type information for previously crawled URLs and predicts the rendering type for URLs that have yet to be crawled and recommends when rendering type detection should be performed.
65
- *
66
- * @experimental
67
65
  */
68
66
  export class RenderingTypePredictor {
69
67
  #detectionRatio;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/playwright",
3
- "version": "4.0.0-beta.232",
3
+ "version": "4.0.0-beta.235",
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.13.0"
@@ -49,13 +49,14 @@
49
49
  "dependencies": {
50
50
  "@apify/datastructures": "^3.0.1",
51
51
  "@apify/timeout": "^1.0.1",
52
- "@crawlee/basic": "4.0.0-beta.232",
53
- "@crawlee/browser": "4.0.0-beta.232",
54
- "@crawlee/browser-pool": "4.0.0-beta.232",
55
- "@crawlee/cheerio": "4.0.0-beta.232",
56
- "@crawlee/core": "4.0.0-beta.232",
57
- "@crawlee/types": "4.0.0-beta.232",
58
- "@crawlee/utils": "4.0.0-beta.232",
52
+ "@crawlee/basic": "4.0.0-beta.235",
53
+ "@crawlee/browser": "4.0.0-beta.235",
54
+ "@crawlee/browser-pool": "4.0.0-beta.235",
55
+ "@crawlee/cheerio": "4.0.0-beta.235",
56
+ "@crawlee/core": "4.0.0-beta.235",
57
+ "@crawlee/http-client": "4.0.0-beta.235",
58
+ "@crawlee/types": "4.0.0-beta.235",
59
+ "@crawlee/utils": "4.0.0-beta.235",
59
60
  "cheerio": "^1.0.0",
60
61
  "domhandler": "^6.0.0",
61
62
  "jquery": "^3.7.1",
@@ -80,5 +81,5 @@
80
81
  }
81
82
  }
82
83
  },
83
- "gitHead": "5eab8f877242d46d7cae13b640d8e1adbf194911"
84
+ "gitHead": "06b640b70f6c6c912a19fd6643574274bdc1a953"
84
85
  }