@crawlee/playwright 4.0.0-rc.3 → 4.0.1-beta.0

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.
package/README.md CHANGED
@@ -34,7 +34,7 @@ Crawlee is available as the [`crawlee`](https://www.npmjs.com/package/crawlee) N
34
34
 
35
35
  We recommend visiting the [Introduction tutorial](https://crawlee.dev/js/docs/introduction) in Crawlee documentation for more information.
36
36
 
37
- > Crawlee requires **Node.js 22.13 or higher**.
37
+ > Crawlee requires **Node.js 22.15 or higher**.
38
38
 
39
39
  ### With Crawlee CLI
40
40
 
@@ -144,6 +144,10 @@ Crawlee is open-source and runs anywhere, but since it's developed by [Apify](ht
144
144
 
145
145
  If you find any bug or issue with Crawlee, please [submit an issue on GitHub](https://github.com/apify/crawlee/issues). For questions, you can ask on [Stack Overflow](https://stackoverflow.com/questions/tagged/apify), in GitHub Discussions or you can join our [Discord server](https://discord.com/invite/jyEM2PRvMU).
146
146
 
147
+ ## Supported versions
148
+
149
+ New features and bug fixes land in the latest major version. The previous major version keeps receiving fixes for high and critical severity vulnerabilities for 12 months after the next major is released, and reaches end of life after that. See the [security policy](https://github.com/apify/crawlee/security/policy) for the current status of each version and for how to report a vulnerability.
150
+
147
151
  ## Contributing
148
152
 
149
153
  Your code contributions are welcome, and you'll be praised to eternity! If you have any ideas for improvements, either submit an issue or create a pull request. For contribution guidelines and the code of conduct, see [CONTRIBUTING.md](https://github.com/apify/crawlee/blob/master/CONTRIBUTING.md).
@@ -2,6 +2,7 @@ import type { BrowserHook, LoadedRequest, RouterHandler, RouteSchemas, RoutesFro
2
2
  import type { BasicCrawlerOptions, CrawlingContext, EnqueueLinksOptions, ExtractLinksOptions, GetUserDataFromRequest, RouterRoutes } from '@crawlee/basic';
3
3
  import { BasicCrawler } from '@crawlee/basic';
4
4
  import { CrawlingRequest } from '@crawlee/browser';
5
+ import type { CheerioCrawlerOptions } from '@crawlee/cheerio';
5
6
  import type { AddRequestsBatchedResult, StorageTransactionView } from '@crawlee/core';
6
7
  import type { Dictionary, Awaitable } from '@crawlee/types';
7
8
  import { type Cheerio, type CheerioAPI } from 'cheerio';
@@ -109,7 +110,20 @@ export interface AdaptiveResultContext {
109
110
  /** The request whose handler produced the results. */
110
111
  request: CrawlingRequest;
111
112
  }
112
- export interface AdaptivePlaywrightCrawlerOptions<ContextExtension = Dictionary<never>, ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<AdaptivePlaywrightCrawlerContext['request']>>, StatisticStateExtension extends AdaptivePlaywrightCrawlerStatisticState = AdaptivePlaywrightCrawlerStatisticState> extends Omit<BasicCrawlerOptions<AdaptivePlaywrightCrawlerContext, ContextExtension, ExtendedContext, Routes, StatisticStateExtension>, 'preNavigationHooks' | 'postNavigationHooks' | 'contextPipelineBuilder'>, Pick<PlaywrightCrawlerOptions, 'launchContext' | 'headless' | 'browserPool' | 'remoteBrowser'> {
113
+ export interface AdaptivePlaywrightCrawlerOptions<ContextExtension = Dictionary<never>, ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<AdaptivePlaywrightCrawlerContext['request']>>, StatisticStateExtension extends AdaptivePlaywrightCrawlerStatisticState = AdaptivePlaywrightCrawlerStatisticState> extends Omit<BasicCrawlerOptions<AdaptivePlaywrightCrawlerContext, ContextExtension, ExtendedContext, Routes, StatisticStateExtension>, 'preNavigationHooks' | 'postNavigationHooks' | 'contextPipelineBuilder'> {
114
+ /**
115
+ * If set to `true`, TLS/SSL certificate errors are ignored in both attempts: see
116
+ * {@link HttpCrawlerOptions.ignoreTlsErrors} for the HTTP-only one, the browser gets Playwright's
117
+ * `ignoreHTTPSErrors` launch option. Can't be combined with `browserOptions.browserPool`,
118
+ * `browserOptions.remoteBrowser` or `browserOptions.launchContext.useIncognitoPages`, which don't use the launch options.
119
+ *
120
+ * @default false
121
+ */
122
+ ignoreTlsErrors?: boolean;
123
+ /** Options of the HTTP-only attempt, forwarded to its {@link CheerioCrawler}. */
124
+ httpOptions?: Pick<CheerioCrawlerOptions, 'additionalMimeTypes'>;
125
+ /** Options of the browser attempt, forwarded to its {@link PlaywrightCrawler}. */
126
+ browserOptions?: Pick<PlaywrightCrawlerOptions, 'launchContext' | 'headless' | 'browserPool' | 'remoteBrowser' | 'ignoreIframes'>;
113
127
  /**
114
128
  * Timeout for the navigation phase of each attempt, in seconds, shared by the `preNavigationHooks`, the
115
129
  * navigation and the `postNavigationHooks`. Applies to both the HTTP-only and the browser attempt. When not
@@ -169,7 +169,9 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
169
169
  */
170
170
  #shutDown = false;
171
171
  constructor(options = {}) {
172
- const { requestHandler, renderingTypeDetectionRatio = 0.1, renderingTypePredictor, resultChecker, shouldPropagateError, resultComparator, statistics, requestHandlerTimeoutSecs = 60, errorHandler, failedRequestHandler, preNavigationHooks = [], postNavigationHooks = [], extendContext, transactionalStorage, navigationTimeoutSecs, launchContext, headless, browserPool, remoteBrowser, ...rest } = options;
172
+ const {
173
+ // Not forwarded to the inner crawlers - an ID may only be held by one live crawler.
174
+ id, requestHandler, renderingTypeDetectionRatio = 0.1, renderingTypePredictor, resultChecker, shouldPropagateError, resultComparator, statistics, requestHandlerTimeoutSecs = 60, errorHandler, failedRequestHandler, preNavigationHooks = [], postNavigationHooks = [], extendContext, transactionalStorage, navigationTimeoutSecs, ignoreTlsErrors = false, httpOptions, browserOptions, ...rest } = options;
173
175
  // The user's value is replaced by `false` in the `super` call below — validate it separately,
174
176
  // wrapped in an object so the error still names the field.
175
177
  parseArgument({ transactionalStorage }, z.object({ transactionalStorage: BasicCrawler.optionsShape.transactionalStorage }), 'AdaptivePlaywrightCrawlerOptions');
@@ -191,8 +193,14 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
191
193
  'attempts. `transactionalStorage: false` is therefore not supported; a write policy ' +
192
194
  'object is accepted and forwarded to the per-attempt transactions.');
193
195
  }
196
+ const { browserPool, remoteBrowser, launchContext } = browserOptions ?? {};
197
+ if (ignoreTlsErrors && (browserPool || remoteBrowser || launchContext?.useIncognitoPages)) {
198
+ throw new Error('AdaptivePlaywrightCrawler: `ignoreTlsErrors` cannot be combined with `browserPool`, `remoteBrowser` ' +
199
+ 'or `launchContext.useIncognitoPages` - configure the browser to ignore TLS errors yourself.');
200
+ }
194
201
  super({
195
202
  ...rest,
203
+ id,
196
204
  errorHandler,
197
205
  failedRequestHandler,
198
206
  requestHandler,
@@ -214,7 +222,7 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
214
222
  this.#individualRequestHandlerTimeoutMillis = requestHandlerTimeoutSecs * 1000;
215
223
  // `renderingTypeDetectionRatio` only configures the default predictor - an injected one brings its own
216
224
  // detection ratio (and its own state), so the option is ignored in that case.
217
- this.#renderingTypePredictor = OwnedOrInjected.resolve(renderingTypePredictor, () => new RenderingTypePredictor({ detectionRatio: renderingTypeDetectionRatio, id: options.id }));
225
+ this.#renderingTypePredictor = OwnedOrInjected.resolve(renderingTypePredictor, () => new RenderingTypePredictor({ detectionRatio: renderingTypeDetectionRatio, id }));
218
226
  this.#attemptWritePolicy = {
219
227
  requestQueue: 'deferred',
220
228
  ...(typeof transactionalStorage === 'object' ? transactionalStorage : {}),
@@ -246,6 +254,8 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
246
254
  // each hook's overrides at runtime regardless of the static type.
247
255
  const staticCrawler = new CheerioCrawler({
248
256
  ...rest,
257
+ ...httpOptions,
258
+ ignoreTlsErrors,
249
259
  statistics: new Statistics({ persistenceOptions: { enable: false } }),
250
260
  preNavigationHooks,
251
261
  postNavigationHooks,
@@ -254,15 +264,18 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
254
264
  });
255
265
  const browserCrawler = new PlaywrightCrawler({
256
266
  ...rest,
267
+ ...browserOptions,
268
+ ...(ignoreTlsErrors && {
269
+ launchContext: {
270
+ ...launchContext,
271
+ launchOptions: { ...launchContext?.launchOptions, ignoreHTTPSErrors: true },
272
+ },
273
+ }),
257
274
  statistics: new Statistics({ persistenceOptions: { enable: false } }),
258
275
  preNavigationHooks: preNavigationHooks,
259
276
  postNavigationHooks: postNavigationHooks,
260
277
  extendContext,
261
278
  navigationTimeoutSecs,
262
- launchContext,
263
- headless,
264
- browserPool,
265
- remoteBrowser,
266
279
  });
267
280
  this.#staticCrawler = staticCrawler;
268
281
  this.#browserCrawler = browserCrawler;
@@ -159,8 +159,7 @@ export declare class PlaywrightCrawler<ContextExtension = Dictionary<never>, Ext
159
159
  }>>;
160
160
  }, z.core.$strict>]>>;
161
161
  onSkippedRequest: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
162
- // @ts-ignore optional peer dependency or compatibility with es2022
163
- httpClient: z.ZodOptional<z.ZodInstanceOf<import("@crawlee/http-client").BaseHttpClient>>;
162
+ httpClient: z.ZodOptional<z.ZodType<Dictionary, unknown, z.core.$ZodTypeInternals<Dictionary, unknown>>>;
164
163
  // @ts-ignore optional peer dependency or compatibility with es2022
165
164
  configuration: z.ZodOptional<z.ZodInstanceOf<import("@crawlee/browser").Configuration>>;
166
165
  storageBackend: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
@@ -217,8 +216,7 @@ export declare class PlaywrightCrawler<ContextExtension = Dictionary<never>, Ext
217
216
  }>>;
218
217
  }, z.core.$strict>]>>;
219
218
  onSkippedRequest: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
220
- // @ts-ignore optional peer dependency or compatibility with es2022
221
- httpClient: z.ZodOptional<z.ZodInstanceOf<import("@crawlee/http-client").BaseHttpClient>>;
219
+ httpClient: z.ZodOptional<z.ZodType<Dictionary, unknown, z.core.$ZodTypeInternals<Dictionary, unknown>>>;
222
220
  // @ts-ignore optional peer dependency or compatibility with es2022
223
221
  configuration: z.ZodOptional<z.ZodInstanceOf<import("@crawlee/browser").Configuration>>;
224
222
  storageBackend: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@crawlee/playwright",
3
- "version": "4.0.0-rc.3",
3
+ "version": "4.0.1-beta.0",
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
- "node": ">=22.13.0"
6
+ "node": ">=22.15.0"
7
7
  },
8
8
  "type": "module",
9
9
  "exports": {
@@ -49,14 +49,14 @@
49
49
  "dependencies": {
50
50
  "@apify/datastructures": "^3.0.1",
51
51
  "@apify/timeout": "^1.1.0",
52
- "@crawlee/basic": "4.0.0-rc.3",
53
- "@crawlee/browser": "4.0.0-rc.3",
54
- "@crawlee/browser-pool": "4.0.0-rc.3",
55
- "@crawlee/cheerio": "4.0.0-rc.3",
56
- "@crawlee/core": "4.0.0-rc.3",
57
- "@crawlee/http-client": "4.0.0-rc.3",
58
- "@crawlee/types": "4.0.0-rc.3",
59
- "@crawlee/utils": "4.0.0-rc.3",
52
+ "@crawlee/basic": "4.0.1-beta.0",
53
+ "@crawlee/browser": "4.0.1-beta.0",
54
+ "@crawlee/browser-pool": "4.0.1-beta.0",
55
+ "@crawlee/cheerio": "4.0.1-beta.0",
56
+ "@crawlee/core": "4.0.1-beta.0",
57
+ "@crawlee/http-client": "4.0.1-beta.0",
58
+ "@crawlee/types": "4.0.1-beta.0",
59
+ "@crawlee/utils": "4.0.1-beta.0",
60
60
  "cheerio": "^1.2.0",
61
61
  "domhandler": "^6.0.1",
62
62
  "jquery": "^3.8.0",
@@ -81,5 +81,5 @@
81
81
  }
82
82
  }
83
83
  },
84
- "gitHead": "c8d256de99bcece26c9f675601dadaf0f2b892f2"
84
+ "gitHead": "ca428c739753e238fc0d60ad1b5b1ae2328b2bfa"
85
85
  }