@crawlee/puppeteer 4.0.0-beta.134 → 4.0.0-beta.136
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/internals/enqueue-links/click-elements.js +2 -1
- package/internals/puppeteer-crawler.d.ts +7 -22
- package/internals/puppeteer-crawler.js +6 -1
- package/internals/puppeteer-launcher.d.ts +4 -0
- package/internals/puppeteer-launcher.js +6 -1
- package/internals/utils/puppeteer_request_interception.js +2 -1
- package/internals/utils/puppeteer_utils.d.ts +3 -3
- package/internals/utils/puppeteer_utils.js +2 -1
- package/package.json +7 -7
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { URL } from 'node:url';
|
|
2
|
-
import { applyRequestTransform, constructUrlPatternObjects, createRequestOptions, filterRequestOptionsByPatterns,
|
|
2
|
+
import { applyRequestTransform, constructUrlPatternObjects, createRequestOptions, filterRequestOptionsByPatterns, urlPatternSchema, Request, serviceLocator, } from '@crawlee/browser';
|
|
3
|
+
import { parseArgument, schemas } from '@crawlee/utils/internal';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
import { addInterceptRequestHandler, removeInterceptRequestHandler } from '../utils/puppeteer_request_interception.js';
|
|
5
6
|
const STARTING_Z_INDEX = 2147400000;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import type { BrowserCrawlerOptions, BrowserCrawlingContext, BrowserHook, GetUserDataFromRequest, RouterHandler, RouterRoutes, RouteSchemas, RoutesFromSchemas } from '@crawlee/browser';
|
|
1
|
+
import type { BrowserCrawlerOptions, BrowserCrawlingContext, BrowserHook, ContextPipeline, CrawlingContext, GetUserDataFromRequest, RouterHandler, RouterRoutes, RouteSchemas, RoutesFromSchemas } from '@crawlee/browser';
|
|
2
2
|
import { BrowserCrawler } from '@crawlee/browser';
|
|
3
3
|
import type { Dictionary } from '@crawlee/types';
|
|
4
4
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
5
5
|
import type { HTTPResponse, LaunchOptions, Page } from 'puppeteer';
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
-
import type { EnqueueLinksByClickingElementsOptions } from './enqueue-links/click-elements.js';
|
|
8
7
|
import type { PuppeteerLaunchContext } from './puppeteer-launcher.js';
|
|
9
|
-
import type {
|
|
10
|
-
import type { BlockRequestsOptions, DirectNavigationOptions, InfiniteScrollOptions, InjectFileOptions, PuppeteerContextUtils, SaveSnapshotOptions } from './utils/puppeteer_utils.js';
|
|
8
|
+
import type { DirectNavigationOptions, PuppeteerContextUtils } from './utils/puppeteer_utils.js';
|
|
11
9
|
export type PuppeteerGoToOptions = NonNullable<Parameters<Page['goto']>[1]>;
|
|
12
10
|
export interface PuppeteerCrawlingContext<UserData extends Dictionary = any> extends BrowserCrawlingContext<Page, HTTPResponse, UserData, PuppeteerGoToOptions>, PuppeteerContextUtils {
|
|
13
11
|
}
|
|
@@ -123,6 +121,9 @@ export interface PuppeteerCrawlerOptions<ContextExtension = Dictionary<never>, E
|
|
|
123
121
|
* @category Crawlers
|
|
124
122
|
*/
|
|
125
123
|
export declare class PuppeteerCrawler<ContextExtension = Dictionary<never>, ExtendedContext extends PuppeteerCrawlingContext = PuppeteerCrawlingContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<PuppeteerCrawlingContext['request']>>, StatisticStateExtension extends object = {}> extends BrowserCrawler<Page, HTTPResponse, LaunchOptions, PuppeteerCrawlingContext, ContextExtension, ExtendedContext, Routes, StatisticStateExtension> {
|
|
124
|
+
/**
|
|
125
|
+
* @internal
|
|
126
|
+
*/
|
|
126
127
|
protected static optionsShape: {
|
|
127
128
|
headless: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>;
|
|
128
129
|
navigationTimeoutSecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
@@ -181,6 +182,7 @@ export declare class PuppeteerCrawler<ContextExtension = Dictionary<never>, Exte
|
|
|
181
182
|
statistics: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
182
183
|
id: z.ZodOptional<z.ZodString>;
|
|
183
184
|
};
|
|
185
|
+
/** @internal */
|
|
184
186
|
protected static optionsSchema: z.ZodObject<{
|
|
185
187
|
headless: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>;
|
|
186
188
|
navigationTimeoutSecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
@@ -243,24 +245,7 @@ export declare class PuppeteerCrawler<ContextExtension = Dictionary<never>, Exte
|
|
|
243
245
|
* All `PuppeteerCrawler` parameters are passed via an options object.
|
|
244
246
|
*/
|
|
245
247
|
constructor(options?: PuppeteerCrawlerOptions<ContextExtension, ExtendedContext, Routes, StatisticStateExtension>);
|
|
246
|
-
|
|
247
|
-
protected buildContextPipeline(): import("@crawlee/browser").ContextPipeline<import("@crawlee/browser").CrawlingContext<Dictionary>, BrowserCrawlingContext<Page, HTTPResponse, Dictionary, Dictionary> & {
|
|
248
|
-
injectFile: (filePath: string, options?: InjectFileOptions) => Promise<unknown>;
|
|
249
|
-
injectJQuery: () => Promise<void>;
|
|
250
|
-
waitForSelector: (selector: string, timeoutMs?: number) => Promise<void>;
|
|
251
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
252
|
-
parseWithCheerio: (selector?: string, timeoutMs?: number) => Promise<import("@crawlee/browser").CheerioAPI>;
|
|
253
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
254
|
-
enqueueLinksByClickingElements: (options: Omit<EnqueueLinksByClickingElementsOptions, "page" | "requestManager">) => Promise<import("@crawlee/types").BatchAddRequestsResult>;
|
|
255
|
-
blockRequests: (options?: BlockRequestsOptions) => Promise<void>;
|
|
256
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
257
|
-
compileScript: (scriptString: string, ctx?: Dictionary) => import("./utils/puppeteer_utils.js").CompiledScriptFunction;
|
|
258
|
-
addInterceptRequestHandler: (handler: InterceptHandler) => Promise<void>;
|
|
259
|
-
removeInterceptRequestHandler: (handler: InterceptHandler) => Promise<void>;
|
|
260
|
-
infiniteScroll: (options?: InfiniteScrollOptions) => Promise<void>;
|
|
261
|
-
saveSnapshot: (options?: SaveSnapshotOptions) => Promise<void>;
|
|
262
|
-
closeCookieModals: () => Promise<void>;
|
|
263
|
-
}>;
|
|
248
|
+
protected buildContextPipeline(): ContextPipeline<CrawlingContext, PuppeteerCrawlingContext>;
|
|
264
249
|
private enhanceContext;
|
|
265
250
|
protected navigationHandler(crawlingContext: PuppeteerCrawlingContext, gotoOptions: DirectNavigationOptions): Promise<HTTPResponse | null>;
|
|
266
251
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assertBrowserPoolNotConfigured, BrowserCrawler, RequestState, Router } from '@crawlee/browser';
|
|
2
|
-
import {
|
|
2
|
+
import { serviceLocator } from '@crawlee/core';
|
|
3
|
+
import { parseArgument } from '@crawlee/utils/internal';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
import { puppeteerBrowserPool, remotePuppeteerBrowserPool } from './puppeteer-browser-pool.js';
|
|
5
6
|
import { gotoExtended, puppeteerUtils } from './utils/puppeteer_utils.js';
|
|
@@ -69,12 +70,16 @@ import { gotoExtended, puppeteerUtils } from './utils/puppeteer_utils.js';
|
|
|
69
70
|
* @category Crawlers
|
|
70
71
|
*/
|
|
71
72
|
export class PuppeteerCrawler extends BrowserCrawler {
|
|
73
|
+
/**
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
72
76
|
static optionsShape = {
|
|
73
77
|
...BrowserCrawler.optionsShape,
|
|
74
78
|
// Deliberately looser than the declared type: Puppeteer's own accepted string values have moved over
|
|
75
79
|
// time (`'new'`/`'old'`, now `'shell'`), and the value is forwarded to it verbatim.
|
|
76
80
|
headless: z.union([z.boolean(), z.string()]).optional(),
|
|
77
81
|
};
|
|
82
|
+
/** @internal */
|
|
78
83
|
static optionsSchema = z.strictObject(PuppeteerCrawler.optionsShape);
|
|
79
84
|
/**
|
|
80
85
|
* All `PuppeteerCrawler` parameters are passed via an options object.
|
|
@@ -68,6 +68,9 @@ export interface PuppeteerLaunchContext extends BrowserLaunchContext<PuppeteerPl
|
|
|
68
68
|
*/
|
|
69
69
|
export declare class PuppeteerLauncher extends BrowserLauncher<PuppeteerPlugin, unknown> {
|
|
70
70
|
readonly configuration: Configuration;
|
|
71
|
+
/**
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
71
74
|
protected static optionsShape: {
|
|
72
75
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
73
76
|
launcher: z.ZodOptional<z.ZodCustom<import("@crawlee/types").Dictionary, import("@crawlee/types").Dictionary>>;
|
|
@@ -81,6 +84,7 @@ export declare class PuppeteerLauncher extends BrowserLauncher<PuppeteerPlugin,
|
|
|
81
84
|
launchOptions: z.ZodOptional<z.ZodCustom<import("@crawlee/types").Dictionary, import("@crawlee/types").Dictionary>>;
|
|
82
85
|
userAgent: z.ZodOptional<z.ZodString>;
|
|
83
86
|
};
|
|
87
|
+
/** @internal */
|
|
84
88
|
protected static optionsSchema: z.ZodObject<{
|
|
85
89
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
86
90
|
launcher: z.ZodOptional<z.ZodCustom<import("@crawlee/types").Dictionary, import("@crawlee/types").Dictionary>>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { BrowserLauncher, Configuration
|
|
1
|
+
import { BrowserLauncher, Configuration } from '@crawlee/browser';
|
|
2
2
|
import { PuppeteerPlugin } from '@crawlee/browser-pool';
|
|
3
|
+
import { parseArgument, schemas } from '@crawlee/utils/internal';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
/**
|
|
5
6
|
* `PuppeteerLauncher` is based on the `BrowserLauncher`. It launches `puppeteer` browser instance.
|
|
@@ -7,10 +8,14 @@ import { z } from 'zod';
|
|
|
7
8
|
*/
|
|
8
9
|
export class PuppeteerLauncher extends BrowserLauncher {
|
|
9
10
|
configuration;
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
10
14
|
static optionsShape = {
|
|
11
15
|
...BrowserLauncher.optionsShape,
|
|
12
16
|
launcher: schemas.anyObject.optional(),
|
|
13
17
|
};
|
|
18
|
+
/** @internal */
|
|
14
19
|
static optionsSchema = z.strictObject(PuppeteerLauncher.optionsShape);
|
|
15
20
|
/**
|
|
16
21
|
* All `PuppeteerLauncher` parameters are passed via an launchContext object.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
-
import {
|
|
2
|
+
import { serviceLocator } from '@crawlee/browser';
|
|
3
|
+
import { parseArgument, schemas } from '@crawlee/utils/internal';
|
|
3
4
|
const pageSchema = schemas.objectWithKeys(['goto', 'evaluate']);
|
|
4
5
|
// We use weak maps here so that the content gets discarded after page gets closed.
|
|
5
6
|
const pageInterceptRequestHandlersMap = new WeakMap(); // Maps page to an array of request interception handlers.
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
import type { Request } from '@crawlee/browser';
|
|
21
21
|
import { Configuration } from '@crawlee/browser';
|
|
22
22
|
import type { BatchAddRequestsResult, Dictionary } from '@crawlee/types';
|
|
23
|
-
import {
|
|
23
|
+
import type { CheerioAPI } from 'cheerio';
|
|
24
24
|
import type { ProtocolMapping } from 'devtools-protocol/types/protocol-mapping.js';
|
|
25
25
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
26
26
|
import type { HTTPResponse, Page, ResponseForRequest } from 'puppeteer';
|
|
@@ -129,7 +129,7 @@ export declare function injectJQuery(page: Page, options?: {
|
|
|
129
129
|
* @param page Puppeteer [`Page`](https://pptr.dev/api/puppeteer.page) object.
|
|
130
130
|
* @param ignoreShadowRoots
|
|
131
131
|
*/
|
|
132
|
-
export declare function parseWithCheerio(page: Page, ignoreShadowRoots?: boolean, ignoreIframes?: boolean): Promise<
|
|
132
|
+
export declare function parseWithCheerio(page: Page, ignoreShadowRoots?: boolean, ignoreIframes?: boolean): Promise<CheerioAPI>;
|
|
133
133
|
/**
|
|
134
134
|
* Forces the Puppeteer browser tab to block loading URLs that match a provided pattern.
|
|
135
135
|
* This is useful to speed up crawling of websites, since it reduces the amount
|
|
@@ -377,7 +377,7 @@ export interface PuppeteerContextUtils {
|
|
|
377
377
|
* });
|
|
378
378
|
* ```
|
|
379
379
|
*/
|
|
380
|
-
parseWithCheerio(selector?: string, timeoutMs?: number): Promise<
|
|
380
|
+
parseWithCheerio(selector?: string, timeoutMs?: number): Promise<CheerioAPI>;
|
|
381
381
|
/**
|
|
382
382
|
* The function finds elements matching a specific CSS selector in a Puppeteer page,
|
|
383
383
|
* clicks all those elements using a mouse move and a left mouse button click and intercepts
|
|
@@ -20,8 +20,9 @@
|
|
|
20
20
|
import { readFile } from 'node:fs/promises';
|
|
21
21
|
import { createRequire } from 'node:module';
|
|
22
22
|
import vm from 'node:vm';
|
|
23
|
-
import { Configuration, KeyValueStore,
|
|
23
|
+
import { Configuration, KeyValueStore, serviceLocator, validators } from '@crawlee/browser';
|
|
24
24
|
import { expandShadowRoots, sleep } from '@crawlee/utils';
|
|
25
|
+
import { parseArgument, schemas } from '@crawlee/utils/internal';
|
|
25
26
|
import { z } from 'zod';
|
|
26
27
|
import { LruCache } from '@apify/datastructures';
|
|
27
28
|
import { enqueueLinksByClickingElements } from '../enqueue-links/click-elements.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/puppeteer",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.136",
|
|
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"
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@apify/datastructures": "^2.0.3",
|
|
51
|
-
"@crawlee/browser": "4.0.0-beta.
|
|
52
|
-
"@crawlee/browser-pool": "4.0.0-beta.
|
|
53
|
-
"@crawlee/core": "4.0.0-beta.
|
|
54
|
-
"@crawlee/types": "4.0.0-beta.
|
|
55
|
-
"@crawlee/utils": "4.0.0-beta.
|
|
51
|
+
"@crawlee/browser": "4.0.0-beta.136",
|
|
52
|
+
"@crawlee/browser-pool": "4.0.0-beta.136",
|
|
53
|
+
"@crawlee/core": "4.0.0-beta.136",
|
|
54
|
+
"@crawlee/types": "4.0.0-beta.136",
|
|
55
|
+
"@crawlee/utils": "4.0.0-beta.136",
|
|
56
56
|
"cheerio": "^1.0.0",
|
|
57
57
|
"devtools-protocol": "*",
|
|
58
58
|
"jquery": "^3.7.1",
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "d425bb9841885b4b71b84ae6fb0bafbdc4a7e978"
|
|
82
82
|
}
|