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

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.
@@ -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';
@@ -234,23 +235,30 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
234
235
  const urls = extractUrlsFromCheerio(cheerioContext.$, options.selector, options.baseUrl ?? cheerioContext.request.loadedUrl);
235
236
  return (await this.#enqueueLinks(urls, options, cheerioContext.request));
236
237
  },
237
- response: cheerioContext.response,
238
+ // The HTTP crawler has already consumed the body; hand out a fresh copy, like the browser side does.
239
+ // HTML bodies are already decoded to UTF-8, so `arrayBuffer()` may disagree with the original headers.
240
+ response: new ResponseWithUrl(cheerioContext.body, cheerioContext.response),
238
241
  };
239
242
  }
240
243
  async #adaptPlaywrightContext(playwrightContext) {
241
244
  // Capture the original response to avoid infinite recursion when the getter is copied to the context
242
245
  const originalResponse = playwrightContext.response;
243
246
  return {
244
- response: new Response(Uint8Array.from(await originalResponse.body()), {
247
+ response: new ResponseWithUrl(Uint8Array.from(await originalResponse.body()), {
245
248
  headers: originalResponse.headers(),
246
249
  status: originalResponse.status(),
247
250
  statusText: originalResponse.statusText(),
251
+ url: originalResponse.url(),
248
252
  }),
249
253
  enqueueLinks: async (options = {}, timeoutMs = 5000) => {
250
254
  // TODO consider using `context.parseWithCheerio` to make this universal and avoid code duplication
251
255
  const selector = options.selector ?? 'a';
252
256
  const locator = playwrightContext.page.locator(selector).first();
253
- await locator.waitFor({ timeout: timeoutMs, state: 'attached' });
257
+ // Wait for client-rendered links, but like the HTTP side, enqueue nothing when there are none.
258
+ await locator.waitFor({ timeout: timeoutMs, state: 'attached' }).catch((error) => {
259
+ if (error.name !== 'TimeoutError')
260
+ throw error;
261
+ });
254
262
  const urls = await extractUrlsFromPage(playwrightContext.page, selector, options.baseUrl ?? playwrightContext.request.loadedUrl);
255
263
  return (await this.#enqueueLinks(urls, options, playwrightContext.request));
256
264
  },
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.233",
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.233",
53
+ "@crawlee/browser": "4.0.0-beta.233",
54
+ "@crawlee/browser-pool": "4.0.0-beta.233",
55
+ "@crawlee/cheerio": "4.0.0-beta.233",
56
+ "@crawlee/core": "4.0.0-beta.233",
57
+ "@crawlee/http-client": "4.0.0-beta.233",
58
+ "@crawlee/types": "4.0.0-beta.233",
59
+ "@crawlee/utils": "4.0.0-beta.233",
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": "3f074fb4fc8bf016aa1740cac0feac5ae84eca36"
84
85
  }