@crawlee/puppeteer 4.0.0-beta.2 → 4.0.0-beta.200
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 +17 -13
- package/index.d.ts +2 -4
- package/index.js +1 -3
- package/internals/enqueue-links/click-elements.d.ts +46 -63
- package/internals/enqueue-links/click-elements.js +65 -54
- package/internals/puppeteer-browser-pool.d.ts +55 -0
- package/internals/puppeteer-browser-pool.js +48 -0
- package/internals/puppeteer-crawler.d.ts +164 -118
- package/internals/puppeteer-crawler.js +89 -69
- package/internals/puppeteer-launcher.d.ts +31 -19
- package/internals/puppeteer-launcher.js +18 -14
- package/internals/utils/puppeteer_request_interception.d.ts +0 -1
- package/internals/utils/puppeteer_request_interception.js +8 -8
- package/internals/utils/puppeteer_utils.d.ts +17 -94
- package/internals/utils/puppeteer_utils.js +91 -196
- package/package.json +11 -12
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/internals/enqueue-links/click-elements.d.ts.map +0 -1
- package/internals/enqueue-links/click-elements.js.map +0 -1
- package/internals/puppeteer-crawler.d.ts.map +0 -1
- package/internals/puppeteer-crawler.js.map +0 -1
- package/internals/puppeteer-launcher.d.ts.map +0 -1
- package/internals/puppeteer-launcher.js.map +0 -1
- package/internals/utils/puppeteer_request_interception.d.ts.map +0 -1
- package/internals/utils/puppeteer_request_interception.js.map +0 -1
- package/internals/utils/puppeteer_utils.d.ts.map +0 -1
- package/internals/utils/puppeteer_utils.js.map +0 -1
- package/tsconfig.build.tsbuildinfo +0 -1
|
@@ -3,6 +3,7 @@ import { BrowserLauncher, Configuration } from '@crawlee/browser';
|
|
|
3
3
|
import { PuppeteerPlugin } from '@crawlee/browser-pool';
|
|
4
4
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
5
5
|
import type { Browser } from 'puppeteer';
|
|
6
|
+
import { z } from 'zod';
|
|
6
7
|
/**
|
|
7
8
|
* Apify extends the launch options of Puppeteer.
|
|
8
9
|
* You can use any of the Puppeteer compatible
|
|
@@ -66,30 +67,42 @@ export interface PuppeteerLaunchContext extends BrowserLaunchContext<PuppeteerPl
|
|
|
66
67
|
* @ignore
|
|
67
68
|
*/
|
|
68
69
|
export declare class PuppeteerLauncher extends BrowserLauncher<PuppeteerPlugin, unknown> {
|
|
69
|
-
readonly
|
|
70
|
+
readonly configuration: Configuration;
|
|
71
|
+
/**
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
70
74
|
protected static optionsShape: {
|
|
75
|
+
proxyUrl: z.ZodOptional<z.ZodURL>;
|
|
76
|
+
useChrome: z.ZodOptional<z.ZodBoolean>;
|
|
77
|
+
useIncognitoPages: z.ZodOptional<z.ZodBoolean>;
|
|
78
|
+
browserPerProxy: z.ZodOptional<z.ZodBoolean>;
|
|
79
|
+
ignoreProxyCertificate: z.ZodOptional<z.ZodBoolean>;
|
|
80
|
+
userDataDir: z.ZodOptional<z.ZodString>;
|
|
71
81
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
proxyUrl: import("ow").StringPredicate & import("ow").BasePredicate<string | undefined>;
|
|
75
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
76
|
-
useChrome: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
82
|
+
launchOptions: z.ZodOptional<z.ZodCustom<import("@crawlee/types").Dictionary, import("@crawlee/types").Dictionary>>;
|
|
83
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
77
84
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
launcher: z.ZodOptional<z.ZodCustom<import("@crawlee/types").Dictionary, import("@crawlee/types").Dictionary>>;
|
|
86
|
+
};
|
|
87
|
+
/** @internal */
|
|
88
|
+
protected static optionsSchema: z.ZodObject<{
|
|
89
|
+
proxyUrl: z.ZodOptional<z.ZodURL>;
|
|
90
|
+
useChrome: z.ZodOptional<z.ZodBoolean>;
|
|
91
|
+
useIncognitoPages: z.ZodOptional<z.ZodBoolean>;
|
|
92
|
+
browserPerProxy: z.ZodOptional<z.ZodBoolean>;
|
|
93
|
+
ignoreProxyCertificate: z.ZodOptional<z.ZodBoolean>;
|
|
94
|
+
userDataDir: z.ZodOptional<z.ZodString>;
|
|
83
95
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
84
|
-
launchOptions: import("
|
|
96
|
+
launchOptions: z.ZodOptional<z.ZodCustom<import("@crawlee/types").Dictionary, import("@crawlee/types").Dictionary>>;
|
|
97
|
+
userAgent: z.ZodOptional<z.ZodString>;
|
|
85
98
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
86
|
-
|
|
87
|
-
}
|
|
99
|
+
launcher: z.ZodOptional<z.ZodCustom<import("@crawlee/types").Dictionary, import("@crawlee/types").Dictionary>>;
|
|
100
|
+
}, z.core.$strict>;
|
|
88
101
|
/**
|
|
89
102
|
* All `PuppeteerLauncher` parameters are passed via an launchContext object.
|
|
90
103
|
*/
|
|
91
|
-
constructor(launchContext?: PuppeteerLaunchContext,
|
|
92
|
-
protected
|
|
104
|
+
constructor(launchContext?: PuppeteerLaunchContext, configuration?: Configuration);
|
|
105
|
+
protected getDefaultHeadlessOption(): boolean;
|
|
93
106
|
}
|
|
94
107
|
/**
|
|
95
108
|
* Launches headless Chrome using Puppeteer pre-configured to work within the Apify platform.
|
|
@@ -119,9 +132,8 @@ export declare class PuppeteerLauncher extends BrowserLauncher<PuppeteerPlugin,
|
|
|
119
132
|
* @param [launchContext]
|
|
120
133
|
* All `PuppeteerLauncher` parameters are passed via an launchContext object.
|
|
121
134
|
* If you want to pass custom `puppeteer.launch(options)` options you can use the `PuppeteerLaunchContext.launchOptions` property.
|
|
122
|
-
* @param [
|
|
135
|
+
* @param [configuration]
|
|
123
136
|
* @returns
|
|
124
137
|
* Promise that resolves to Puppeteer's `Browser` instance.
|
|
125
138
|
*/
|
|
126
|
-
export declare function launchPuppeteer(launchContext?: PuppeteerLaunchContext,
|
|
127
|
-
//# sourceMappingURL=puppeteer-launcher.d.ts.map
|
|
139
|
+
export declare function launchPuppeteer(launchContext?: PuppeteerLaunchContext, configuration?: Configuration): Promise<Browser>;
|
|
@@ -1,31 +1,36 @@
|
|
|
1
1
|
import { BrowserLauncher, Configuration } from '@crawlee/browser';
|
|
2
2
|
import { PuppeteerPlugin } from '@crawlee/browser-pool';
|
|
3
|
-
import
|
|
3
|
+
import { parseArgument, schemas } from '@crawlee/utils/internal';
|
|
4
|
+
import { z } from 'zod';
|
|
4
5
|
/**
|
|
5
6
|
* `PuppeteerLauncher` is based on the `BrowserLauncher`. It launches `puppeteer` browser instance.
|
|
6
7
|
* @ignore
|
|
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
|
-
launcher:
|
|
16
|
+
launcher: schemas.anyObject.optional(),
|
|
13
17
|
};
|
|
18
|
+
/** @internal */
|
|
19
|
+
static optionsSchema = z.strictObject(PuppeteerLauncher.optionsShape);
|
|
14
20
|
/**
|
|
15
21
|
* All `PuppeteerLauncher` parameters are passed via an launchContext object.
|
|
16
22
|
*/
|
|
17
|
-
constructor(launchContext = {},
|
|
18
|
-
|
|
19
|
-
const { launcher = BrowserLauncher.requireLauncherOrThrow('puppeteer', 'apify/actor-node-puppeteer-chrome'), ...browserLauncherOptions } = launchContext;
|
|
23
|
+
constructor(launchContext = {}, configuration = Configuration.getGlobalConfiguration()) {
|
|
24
|
+
const { launcher = BrowserLauncher.requireLauncherOrThrow('puppeteer', 'apify/actor-node-puppeteer-chrome'), ...browserLauncherOptions } = parseArgument(launchContext, PuppeteerLauncher.optionsSchema, 'PuppeteerLaunchContext');
|
|
20
25
|
super({
|
|
21
26
|
...browserLauncherOptions,
|
|
22
27
|
launcher,
|
|
23
|
-
},
|
|
24
|
-
this.
|
|
28
|
+
}, configuration);
|
|
29
|
+
this.configuration = configuration;
|
|
25
30
|
this.Plugin = PuppeteerPlugin;
|
|
26
31
|
}
|
|
27
|
-
|
|
28
|
-
const headless = super.
|
|
32
|
+
getDefaultHeadlessOption() {
|
|
33
|
+
const headless = super.getDefaultHeadlessOption();
|
|
29
34
|
return headless ? 'new' : headless;
|
|
30
35
|
}
|
|
31
36
|
}
|
|
@@ -57,12 +62,11 @@ export class PuppeteerLauncher extends BrowserLauncher {
|
|
|
57
62
|
* @param [launchContext]
|
|
58
63
|
* All `PuppeteerLauncher` parameters are passed via an launchContext object.
|
|
59
64
|
* If you want to pass custom `puppeteer.launch(options)` options you can use the `PuppeteerLaunchContext.launchOptions` property.
|
|
60
|
-
* @param [
|
|
65
|
+
* @param [configuration]
|
|
61
66
|
* @returns
|
|
62
67
|
* Promise that resolves to Puppeteer's `Browser` instance.
|
|
63
68
|
*/
|
|
64
|
-
export async function launchPuppeteer(launchContext,
|
|
65
|
-
const puppeteerLauncher = new PuppeteerLauncher(launchContext,
|
|
69
|
+
export async function launchPuppeteer(launchContext, configuration = Configuration.getGlobalConfiguration()) {
|
|
70
|
+
const puppeteerLauncher = new PuppeteerLauncher(launchContext, configuration);
|
|
66
71
|
return puppeteerLauncher.launch();
|
|
67
72
|
}
|
|
68
|
-
//# sourceMappingURL=puppeteer-launcher.js.map
|
|
@@ -58,4 +58,3 @@ export declare function addInterceptRequestHandler(page: Page, handler: Intercep
|
|
|
58
58
|
* @param handler Request interception handler.
|
|
59
59
|
*/
|
|
60
60
|
export declare function removeInterceptRequestHandler(page: Page, handler: InterceptHandler): Promise<void>;
|
|
61
|
-
//# sourceMappingURL=puppeteer_request_interception.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import { serviceLocator } from '@crawlee/browser';
|
|
3
|
+
import { parseArgument, schemas } from '@crawlee/utils/internal';
|
|
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.
|
|
6
7
|
const pageInterceptRequestMasterHandlerMap = new WeakMap(); // Maps page to master request interception handler.
|
|
@@ -137,8 +138,8 @@ async function handleRequest(request, interceptRequestHandlers) {
|
|
|
137
138
|
* @param handler Request interception handler.
|
|
138
139
|
*/
|
|
139
140
|
export async function addInterceptRequestHandler(page, handler) {
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
parseArgument(page, pageSchema);
|
|
142
|
+
parseArgument(handler, schemas.anyFunction);
|
|
142
143
|
if (!pageInterceptRequestHandlersMap.has(page)) {
|
|
143
144
|
pageInterceptRequestHandlersMap.set(page, []);
|
|
144
145
|
}
|
|
@@ -174,8 +175,8 @@ export async function addInterceptRequestHandler(page, handler) {
|
|
|
174
175
|
* @param handler Request interception handler.
|
|
175
176
|
*/
|
|
176
177
|
export async function removeInterceptRequestHandler(page, handler) {
|
|
177
|
-
|
|
178
|
-
|
|
178
|
+
parseArgument(page, pageSchema);
|
|
179
|
+
parseArgument(handler, schemas.anyFunction);
|
|
179
180
|
const handlersArray = pageInterceptRequestHandlersMap.get(page).filter((item) => item !== handler);
|
|
180
181
|
pageInterceptRequestHandlersMap.set(page, handlersArray);
|
|
181
182
|
if (handlersArray.length === 0) {
|
|
@@ -194,7 +195,7 @@ export async function removeInterceptRequestHandler(page, handler) {
|
|
|
194
195
|
interceptedRequestsInProgress.removeListener('delete', onDelete);
|
|
195
196
|
}
|
|
196
197
|
catch (error) {
|
|
197
|
-
|
|
198
|
+
serviceLocator.getLogger().debug('Error while disabling request interception', { error });
|
|
198
199
|
}
|
|
199
200
|
}
|
|
200
201
|
};
|
|
@@ -207,4 +208,3 @@ async function disableRequestInterception(page) {
|
|
|
207
208
|
const requestHandler = pageInterceptRequestMasterHandlerMap.get(page);
|
|
208
209
|
page.off('request', requestHandler);
|
|
209
210
|
}
|
|
210
|
-
//# sourceMappingURL=puppeteer_request_interception.js.map
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* **Example usage:**
|
|
6
6
|
*
|
|
7
7
|
* ```javascript
|
|
8
|
-
* import { launchPuppeteer,
|
|
8
|
+
* import { launchPuppeteer, puppeteerUtils } from 'crawlee';
|
|
9
9
|
*
|
|
10
10
|
* // Open https://www.example.com in Puppeteer
|
|
11
11
|
* const browser = await launchPuppeteer();
|
|
@@ -13,20 +13,18 @@
|
|
|
13
13
|
* await page.goto('https://www.example.com');
|
|
14
14
|
*
|
|
15
15
|
* // Inject jQuery into a page
|
|
16
|
-
* await
|
|
16
|
+
* await puppeteerUtils.injectJQuery(page);
|
|
17
17
|
* ```
|
|
18
18
|
* @module puppeteerUtils
|
|
19
19
|
*/
|
|
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 {
|
|
24
|
-
import type { ProtocolMapping } from 'devtools-protocol/types/protocol-mapping.js';
|
|
23
|
+
import type { CheerioAPI } from 'cheerio';
|
|
25
24
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
26
|
-
import type { HTTPResponse, Page
|
|
25
|
+
import type { HTTPResponse, Page } from 'puppeteer';
|
|
27
26
|
import type { EnqueueLinksByClickingElementsOptions } from '../enqueue-links/click-elements.js';
|
|
28
27
|
import { enqueueLinksByClickingElements } from '../enqueue-links/click-elements.js';
|
|
29
|
-
import type { PuppeteerCrawlerOptions, PuppeteerCrawlingContext } from '../puppeteer-crawler.js';
|
|
30
28
|
import type { InterceptHandler } from './puppeteer_request_interception.js';
|
|
31
29
|
import { addInterceptRequestHandler, removeInterceptRequestHandler } from './puppeteer_request_interception.js';
|
|
32
30
|
export interface DirectNavigationOptions {
|
|
@@ -102,7 +100,7 @@ export declare function injectFile(page: Page, filePath: string, options?: Injec
|
|
|
102
100
|
*
|
|
103
101
|
* **Example usage:**
|
|
104
102
|
* ```javascript
|
|
105
|
-
* await
|
|
103
|
+
* await puppeteerUtils.injectJQuery(page);
|
|
106
104
|
* const title = await page.evaluate(() => {
|
|
107
105
|
* return $('head title').text();
|
|
108
106
|
* });
|
|
@@ -123,14 +121,14 @@ export declare function injectJQuery(page: Page, options?: {
|
|
|
123
121
|
*
|
|
124
122
|
* **Example usage:**
|
|
125
123
|
* ```javascript
|
|
126
|
-
* const $ = await
|
|
124
|
+
* const $ = await puppeteerUtils.parseWithCheerio(page);
|
|
127
125
|
* const title = $('title').text();
|
|
128
126
|
* ```
|
|
129
127
|
*
|
|
130
128
|
* @param page Puppeteer [`Page`](https://pptr.dev/api/puppeteer.page) object.
|
|
131
129
|
* @param ignoreShadowRoots
|
|
132
130
|
*/
|
|
133
|
-
export declare function parseWithCheerio(page: Page, ignoreShadowRoots?: boolean, ignoreIframes?: boolean): Promise<
|
|
131
|
+
export declare function parseWithCheerio(page: Page, ignoreShadowRoots?: boolean, ignoreIframes?: boolean): Promise<CheerioAPI>;
|
|
134
132
|
/**
|
|
135
133
|
* Forces the Puppeteer browser tab to block loading URLs that match a provided pattern.
|
|
136
134
|
* This is useful to speed up crawling of websites, since it reduces the amount
|
|
@@ -157,13 +155,13 @@ export declare function parseWithCheerio(page: Page, ignoreShadowRoots?: boolean
|
|
|
157
155
|
*
|
|
158
156
|
* **Example usage**
|
|
159
157
|
* ```javascript
|
|
160
|
-
* import { launchPuppeteer,
|
|
158
|
+
* import { launchPuppeteer, puppeteerUtils } from 'crawlee';
|
|
161
159
|
*
|
|
162
160
|
* const browser = await launchPuppeteer();
|
|
163
161
|
* const page = await browser.newPage();
|
|
164
162
|
*
|
|
165
163
|
* // Block all requests to URLs that include `adsbygoogle.js` and also all defaults.
|
|
166
|
-
* await
|
|
164
|
+
* await puppeteerUtils.blockRequests(page, {
|
|
167
165
|
* extraUrlPatterns: ['adsbygoogle.js'],
|
|
168
166
|
* });
|
|
169
167
|
*
|
|
@@ -174,33 +172,6 @@ export declare function parseWithCheerio(page: Page, ignoreShadowRoots?: boolean
|
|
|
174
172
|
* @param [options]
|
|
175
173
|
*/
|
|
176
174
|
export declare function blockRequests(page: Page, options?: BlockRequestsOptions): Promise<void>;
|
|
177
|
-
/**
|
|
178
|
-
* @internal
|
|
179
|
-
*/
|
|
180
|
-
export declare function sendCDPCommand<T extends keyof ProtocolMapping.Commands>(page: Page, command: T, ...args: ProtocolMapping.Commands[T]['paramsType']): Promise<ProtocolMapping.Commands[T]['returnType']>;
|
|
181
|
-
/**
|
|
182
|
-
* `blockResources()` has a high impact on performance in recent versions of Puppeteer.
|
|
183
|
-
* Until this resolves, please use `utils.puppeteer.blockRequests()`.
|
|
184
|
-
* @deprecated
|
|
185
|
-
*/
|
|
186
|
-
export declare const blockResources: (page: Page, resourceTypes?: string[]) => Promise<void>;
|
|
187
|
-
/**
|
|
188
|
-
* *NOTE:* In recent versions of Puppeteer using this function entirely disables browser cache which resolves in sub-optimal
|
|
189
|
-
* performance. Until this resolves, we suggest just relying on the in-browser cache unless absolutely necessary.
|
|
190
|
-
*
|
|
191
|
-
* Enables caching of intercepted responses into a provided object. Automatically enables request interception in Puppeteer.
|
|
192
|
-
* *IMPORTANT*: Caching responses stores them to memory, so too loose rules could cause memory leaks for longer running crawlers.
|
|
193
|
-
* This issue should be resolved or atleast mitigated in future iterations of this feature.
|
|
194
|
-
* @param page
|
|
195
|
-
* Puppeteer [`Page`](https://pptr.dev/api/puppeteer.page) object.
|
|
196
|
-
* @param cache
|
|
197
|
-
* Object in which responses are stored
|
|
198
|
-
* @param responseUrlRules
|
|
199
|
-
* List of rules that are used to check if the response should be cached.
|
|
200
|
-
* String rules are compared as page.url().includes(rule) while RegExp rules are evaluated as rule.test(page.url()).
|
|
201
|
-
* @deprecated
|
|
202
|
-
*/
|
|
203
|
-
export declare function cacheResponses(page: Page, cache: Dictionary<Partial<ResponseForRequest>>, responseUrlRules: (string | RegExp)[]): Promise<void>;
|
|
204
175
|
/**
|
|
205
176
|
* Compiles a Puppeteer script into an async function that may be executed at any time
|
|
206
177
|
* by providing it with the following object:
|
|
@@ -306,9 +277,9 @@ export interface SaveSnapshotOptions {
|
|
|
306
277
|
keyValueStoreName?: string | null;
|
|
307
278
|
/**
|
|
308
279
|
* Configuration of the crawler that will be used to save the snapshot.
|
|
309
|
-
* @default Configuration.
|
|
280
|
+
* @default Configuration.getGlobalConfiguration()
|
|
310
281
|
*/
|
|
311
|
-
|
|
282
|
+
configuration?: Configuration;
|
|
312
283
|
}
|
|
313
284
|
/**
|
|
314
285
|
* Saves a full screenshot and HTML of the current page into a Key-Value store.
|
|
@@ -316,8 +287,6 @@ export interface SaveSnapshotOptions {
|
|
|
316
287
|
* @param [options]
|
|
317
288
|
*/
|
|
318
289
|
export declare function saveSnapshot(page: Page, options?: SaveSnapshotOptions): Promise<void>;
|
|
319
|
-
export declare function closeCookieModals(page: Page): Promise<void>;
|
|
320
|
-
/** @internal */
|
|
321
290
|
export interface PuppeteerContextUtils {
|
|
322
291
|
/**
|
|
323
292
|
* Injects a JavaScript file into current `page`.
|
|
@@ -379,7 +348,7 @@ export interface PuppeteerContextUtils {
|
|
|
379
348
|
* });
|
|
380
349
|
* ```
|
|
381
350
|
*/
|
|
382
|
-
parseWithCheerio(selector?: string, timeoutMs?: number): Promise<
|
|
351
|
+
parseWithCheerio(selector?: string, timeoutMs?: number): Promise<CheerioAPI>;
|
|
383
352
|
/**
|
|
384
353
|
* The function finds elements matching a specific CSS selector in a Puppeteer page,
|
|
385
354
|
* clicks all those elements using a mouse move and a left mouse button click and intercepts
|
|
@@ -389,8 +358,7 @@ export interface PuppeteerContextUtils {
|
|
|
389
358
|
* in `href` elements, but rather navigations are triggered in click handlers.
|
|
390
359
|
* If you're looking to find URLs in `href` attributes of the page, see {@link enqueueLinks}.
|
|
391
360
|
*
|
|
392
|
-
* Optionally, the function allows you to filter the target links' URLs using an array of
|
|
393
|
-
* and override settings of the enqueued {@link Request} objects.
|
|
361
|
+
* Optionally, the function allows you to filter the target links' URLs using an array of glob or regexp patterns.
|
|
394
362
|
*
|
|
395
363
|
* **IMPORTANT**: To be able to do this, this function uses various mutations on the page,
|
|
396
364
|
* such as changing the Z-index of elements being clicked and their visibility. Therefore,
|
|
@@ -411,9 +379,9 @@ export interface PuppeteerContextUtils {
|
|
|
411
379
|
* async requestHandler({ enqueueLinksByClickingElements }) {
|
|
412
380
|
* await enqueueLinksByClickingElements({
|
|
413
381
|
* selector: 'a.product-detail',
|
|
414
|
-
*
|
|
415
|
-
* 'https://www.example.com/handbags/**'
|
|
416
|
-
* 'https://www.example.com/purses/**'
|
|
382
|
+
* include: [
|
|
383
|
+
* 'https://www.example.com/handbags/**',
|
|
384
|
+
* 'https://www.example.com/purses/**',
|
|
417
385
|
* ],
|
|
418
386
|
* });
|
|
419
387
|
* });
|
|
@@ -421,7 +389,7 @@ export interface PuppeteerContextUtils {
|
|
|
421
389
|
*
|
|
422
390
|
* @returns Promise that resolves to {@link BatchAddRequestsResult} object.
|
|
423
391
|
*/
|
|
424
|
-
enqueueLinksByClickingElements(options: Omit<EnqueueLinksByClickingElementsOptions, 'page' | '
|
|
392
|
+
enqueueLinksByClickingElements(options: Omit<EnqueueLinksByClickingElementsOptions, 'page' | 'requestManager'>): Promise<BatchAddRequestsResult>;
|
|
425
393
|
/**
|
|
426
394
|
* Forces the Puppeteer browser tab to block loading URLs that match a provided pattern.
|
|
427
395
|
* This is useful to speed up crawling of websites, since it reduces the amount
|
|
@@ -459,27 +427,6 @@ export interface PuppeteerContextUtils {
|
|
|
459
427
|
* ```
|
|
460
428
|
*/
|
|
461
429
|
blockRequests(options?: BlockRequestsOptions): Promise<void>;
|
|
462
|
-
/**
|
|
463
|
-
* `blockResources()` has a high impact on performance in recent versions of Puppeteer.
|
|
464
|
-
* Until this resolves, please use `utils.puppeteer.blockRequests()`.
|
|
465
|
-
* @deprecated
|
|
466
|
-
*/
|
|
467
|
-
blockResources(resourceTypes?: string[]): Promise<void>;
|
|
468
|
-
/**
|
|
469
|
-
* *NOTE:* In recent versions of Puppeteer using this function entirely disables browser cache which resolves in sub-optimal
|
|
470
|
-
* performance. Until this resolves, we suggest just relying on the in-browser cache unless absolutely necessary.
|
|
471
|
-
*
|
|
472
|
-
* Enables caching of intercepted responses into a provided object. Automatically enables request interception in Puppeteer.
|
|
473
|
-
* *IMPORTANT*: Caching responses stores them to memory, so too loose rules could cause memory leaks for longer running crawlers.
|
|
474
|
-
* This issue should be resolved or atleast mitigated in future iterations of this feature.
|
|
475
|
-
* @param cache
|
|
476
|
-
* Object in which responses are stored
|
|
477
|
-
* @param responseUrlRules
|
|
478
|
-
* List of rules that are used to check if the response should be cached.
|
|
479
|
-
* String rules are compared as page.url().includes(rule) while RegExp rules are evaluated as rule.test(page.url()).
|
|
480
|
-
* @deprecated
|
|
481
|
-
*/
|
|
482
|
-
cacheResponses(cache: Dictionary<Partial<ResponseForRequest>>, responseUrlRules: (string | RegExp)[]): Promise<void>;
|
|
483
430
|
/**
|
|
484
431
|
* Compiles a Puppeteer script into an async function that may be executed at any time
|
|
485
432
|
* by providing it with the following object:
|
|
@@ -572,29 +519,5 @@ export interface PuppeteerContextUtils {
|
|
|
572
519
|
* Saves a full screenshot and HTML of the current page into a Key-Value store.
|
|
573
520
|
*/
|
|
574
521
|
saveSnapshot(options?: SaveSnapshotOptions): Promise<void>;
|
|
575
|
-
/**
|
|
576
|
-
* Tries to close cookie consent modals on the page. Based on the I Don't Care About Cookies browser extension.
|
|
577
|
-
*/
|
|
578
|
-
closeCookieModals(): Promise<void>;
|
|
579
522
|
}
|
|
580
|
-
/** @internal */
|
|
581
|
-
export declare function registerUtilsToContext(context: PuppeteerCrawlingContext, crawlerOptions: PuppeteerCrawlerOptions): void;
|
|
582
523
|
export { enqueueLinksByClickingElements, addInterceptRequestHandler, removeInterceptRequestHandler };
|
|
583
|
-
/** @internal */
|
|
584
|
-
export declare const puppeteerUtils: {
|
|
585
|
-
injectFile: typeof injectFile;
|
|
586
|
-
injectJQuery: typeof injectJQuery;
|
|
587
|
-
enqueueLinksByClickingElements: typeof enqueueLinksByClickingElements;
|
|
588
|
-
blockRequests: typeof blockRequests;
|
|
589
|
-
blockResources: (page: Page, resourceTypes?: string[]) => Promise<void>;
|
|
590
|
-
cacheResponses: typeof cacheResponses;
|
|
591
|
-
compileScript: typeof compileScript;
|
|
592
|
-
gotoExtended: typeof gotoExtended;
|
|
593
|
-
addInterceptRequestHandler: typeof addInterceptRequestHandler;
|
|
594
|
-
removeInterceptRequestHandler: typeof removeInterceptRequestHandler;
|
|
595
|
-
infiniteScroll: typeof infiniteScroll;
|
|
596
|
-
saveSnapshot: typeof saveSnapshot;
|
|
597
|
-
parseWithCheerio: typeof parseWithCheerio;
|
|
598
|
-
closeCookieModals: typeof closeCookieModals;
|
|
599
|
-
};
|
|
600
|
-
//# sourceMappingURL=puppeteer_utils.d.ts.map
|