@crawlee/playwright 4.0.0-beta.81 → 4.0.0-beta.82
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.
|
@@ -79,13 +79,11 @@ interface AdaptiveHookContext extends Pick<AdaptivePlaywrightCrawlerContext, 'id
|
|
|
79
79
|
request: Request;
|
|
80
80
|
gotoOptions?: PlaywrightGotoOptions;
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
interface AdaptivePostNavigationHook extends BrowserHook<Omit<AdaptiveHookContext, 'request'> & {
|
|
82
|
+
type AdaptiveHook<ContextExtension = Dictionary<never>> = BrowserHook<AdaptiveHookContext, ContextExtension>;
|
|
83
|
+
type AdaptivePostNavigationHook<ContextExtension = Dictionary<never>> = BrowserHook<Omit<AdaptiveHookContext, 'request'> & {
|
|
85
84
|
request: LoadedRequest<Request>;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export interface AdaptivePlaywrightCrawlerOptions<ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext> extends Omit<BasicCrawlerOptions<AdaptivePlaywrightCrawlerContext, ExtendedContext>, 'preNavigationHooks' | 'postNavigationHooks'> {
|
|
85
|
+
}, ContextExtension>;
|
|
86
|
+
export interface AdaptivePlaywrightCrawlerOptions<ContextExtension = Dictionary<never>, ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext & ContextExtension> extends Omit<BasicCrawlerOptions<AdaptivePlaywrightCrawlerContext, ContextExtension, ExtendedContext>, 'preNavigationHooks' | 'postNavigationHooks'> {
|
|
89
87
|
/**
|
|
90
88
|
* Async functions that are sequentially evaluated before the navigation. Good for setting additional cookies.
|
|
91
89
|
* The function accepts a subset of the crawling context. If you attempt to access the `page` property during HTTP-only crawling,
|
|
@@ -94,7 +92,7 @@ export interface AdaptivePlaywrightCrawlerOptions<ExtendedContext extends Adapti
|
|
|
94
92
|
* A hook may optionally return a partial object whose properties are merged into the crawling context,
|
|
95
93
|
* allowing the hook to override context members for subsequent hooks and pipeline stages.
|
|
96
94
|
*/
|
|
97
|
-
preNavigationHooks?: AdaptiveHook[];
|
|
95
|
+
preNavigationHooks?: AdaptiveHook<ContextExtension>[];
|
|
98
96
|
/**
|
|
99
97
|
* Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful.
|
|
100
98
|
* The function accepts a subset of the crawling context. If you attempt to access the `page` property during HTTP-only crawling,
|
|
@@ -103,7 +101,7 @@ export interface AdaptivePlaywrightCrawlerOptions<ExtendedContext extends Adapti
|
|
|
103
101
|
* A hook may optionally return a partial object whose properties are merged into the crawling context
|
|
104
102
|
* (e.g. to override `response` after solving a challenge).
|
|
105
103
|
*/
|
|
106
|
-
postNavigationHooks?: AdaptivePostNavigationHook[];
|
|
104
|
+
postNavigationHooks?: AdaptivePostNavigationHook<ContextExtension>[];
|
|
107
105
|
/**
|
|
108
106
|
* Specifies the frequency of rendering type detection checks - 0.1 means roughly 10% of requests.
|
|
109
107
|
* Defaults to 0.1 (so 10%).
|
|
@@ -177,7 +175,7 @@ export interface AdaptivePlaywrightCrawlerOptions<ExtendedContext extends Adapti
|
|
|
177
175
|
*
|
|
178
176
|
* @experimental
|
|
179
177
|
*/
|
|
180
|
-
export declare class AdaptivePlaywrightCrawler<ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext> extends BasicCrawler<AdaptivePlaywrightCrawlerContext, ExtendedContext> {
|
|
178
|
+
export declare class AdaptivePlaywrightCrawler<ContextExtension = Dictionary<never>, ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext & ContextExtension> extends BasicCrawler<AdaptivePlaywrightCrawlerContext, ContextExtension, ExtendedContext> {
|
|
181
179
|
private renderingTypePredictor;
|
|
182
180
|
private resultChecker;
|
|
183
181
|
private shouldPropagateError;
|
|
@@ -190,7 +188,7 @@ export declare class AdaptivePlaywrightCrawler<ExtendedContext extends AdaptiveP
|
|
|
190
188
|
private resultObjects;
|
|
191
189
|
private inFlightRenderingTypeDetections;
|
|
192
190
|
private teardownHooks;
|
|
193
|
-
constructor(options?: AdaptivePlaywrightCrawlerOptions<ExtendedContext>);
|
|
191
|
+
constructor(options?: AdaptivePlaywrightCrawlerOptions<ContextExtension, ExtendedContext>);
|
|
194
192
|
protected _init(): Promise<void>;
|
|
195
193
|
protected buildContextPipeline(): ContextPipeline<CrawlingContext<Dictionary>, CrawlingContext<Dictionary> & {
|
|
196
194
|
readonly request: LoadedRequest<Request<Dictionary>>;
|
|
@@ -122,10 +122,14 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
|
|
|
122
122
|
}));
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
-
//
|
|
126
|
-
// `
|
|
127
|
-
//
|
|
128
|
-
//
|
|
125
|
+
// `extendContext` is forwarded to the inner crawlers, which run it *before* navigation (see
|
|
126
|
+
// `BasicCrawler`), keeping the behavior consistent with the non-adaptive crawlers: the
|
|
127
|
+
// extension is visible to the pre/post-navigation hooks and the request handler, but cannot
|
|
128
|
+
// access navigation-dependent members (`page`, `response`, `$`, ...).
|
|
129
|
+
//
|
|
130
|
+
// The adaptive hooks target a subset context (`AdaptiveHookContext`); the casts to the inner
|
|
131
|
+
// crawlers' `PlaywrightHook` type relax that nominal difference. The `ContextPipeline` merges
|
|
132
|
+
// each hook's overrides at runtime regardless of the static type.
|
|
129
133
|
const staticCrawler = new CheerioCrawler({
|
|
130
134
|
...rest,
|
|
131
135
|
statisticsOptions: {
|
|
@@ -133,6 +137,7 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
|
|
|
133
137
|
},
|
|
134
138
|
preNavigationHooks,
|
|
135
139
|
postNavigationHooks,
|
|
140
|
+
extendContext,
|
|
136
141
|
});
|
|
137
142
|
const browserCrawler = new PlaywrightCrawler({
|
|
138
143
|
...rest,
|
|
@@ -141,21 +146,14 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
|
|
|
141
146
|
},
|
|
142
147
|
preNavigationHooks: preNavigationHooks,
|
|
143
148
|
postNavigationHooks: postNavigationHooks,
|
|
149
|
+
extendContext,
|
|
144
150
|
});
|
|
145
151
|
this.teardownHooks.push(browserCrawler.teardown.bind(browserCrawler));
|
|
146
|
-
this.staticContextPipeline = staticCrawler.contextPipeline
|
|
147
|
-
.compose({
|
|
152
|
+
this.staticContextPipeline = staticCrawler.contextPipeline.compose({
|
|
148
153
|
action: this.adaptCheerioContext.bind(this),
|
|
149
|
-
})
|
|
150
|
-
.compose({
|
|
151
|
-
action: async (context) => extendContext ? await extendContext(context) : context,
|
|
152
154
|
});
|
|
153
|
-
this.browserContextPipeline = browserCrawler.contextPipeline
|
|
154
|
-
.compose({
|
|
155
|
+
this.browserContextPipeline = browserCrawler.contextPipeline.compose({
|
|
155
156
|
action: this.adaptPlaywrightContext.bind(this),
|
|
156
|
-
})
|
|
157
|
-
.compose({
|
|
158
|
-
action: async (context) => extendContext ? await extendContext(context) : context,
|
|
159
157
|
});
|
|
160
158
|
this.stats = new AdaptivePlaywrightCrawlerStatistics({
|
|
161
159
|
logMessage: `${this.log.getOptions().prefix} request statistics:`,
|
|
@@ -59,7 +59,7 @@ export interface PlaywrightCrawlerOptions<ContextExtension = Dictionary<never>,
|
|
|
59
59
|
* ]
|
|
60
60
|
* ```
|
|
61
61
|
*/
|
|
62
|
-
preNavigationHooks?:
|
|
62
|
+
preNavigationHooks?: BrowserHook<PlaywrightCrawlingContext, ContextExtension>[];
|
|
63
63
|
/**
|
|
64
64
|
* Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful.
|
|
65
65
|
* The function accepts `crawlingContext` as the only parameter. A hook may optionally return a partial object
|
|
@@ -76,7 +76,7 @@ export interface PlaywrightCrawlerOptions<ContextExtension = Dictionary<never>,
|
|
|
76
76
|
* ]
|
|
77
77
|
* ```
|
|
78
78
|
*/
|
|
79
|
-
postNavigationHooks?:
|
|
79
|
+
postNavigationHooks?: BrowserHook<PlaywrightCrawlingContext, ContextExtension>[];
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
82
|
* Provides a simple framework for parallel crawling of web pages
|
|
@@ -243,7 +243,7 @@ export declare class PlaywrightCrawler<ContextExtension = Dictionary<never>, Ext
|
|
|
243
243
|
/**
|
|
244
244
|
* All `PlaywrightCrawler` parameters are passed via an options object.
|
|
245
245
|
*/
|
|
246
|
-
constructor(options?: PlaywrightCrawlerOptions<ExtendedContext>);
|
|
246
|
+
constructor(options?: PlaywrightCrawlerOptions<ContextExtension, ExtendedContext>);
|
|
247
247
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
248
248
|
protected buildContextPipeline(): import("@crawlee/browser").ContextPipeline<import("@crawlee/browser").CrawlingContext<Dictionary>, BrowserCrawlingContext<Page, Response, Dictionary, Dictionary> & {
|
|
249
249
|
injectFile: (filePath: string, options?: InjectFileOptions) => Promise<unknown>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/playwright",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.82",
|
|
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"
|
|
@@ -49,13 +49,13 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@apify/datastructures": "^2.0.3",
|
|
51
51
|
"@apify/timeout": "^0.3.2",
|
|
52
|
-
"@crawlee/basic": "4.0.0-beta.
|
|
53
|
-
"@crawlee/browser": "4.0.0-beta.
|
|
54
|
-
"@crawlee/browser-pool": "4.0.0-beta.
|
|
55
|
-
"@crawlee/cheerio": "4.0.0-beta.
|
|
56
|
-
"@crawlee/core": "4.0.0-beta.
|
|
57
|
-
"@crawlee/types": "4.0.0-beta.
|
|
58
|
-
"@crawlee/utils": "4.0.0-beta.
|
|
52
|
+
"@crawlee/basic": "4.0.0-beta.82",
|
|
53
|
+
"@crawlee/browser": "4.0.0-beta.82",
|
|
54
|
+
"@crawlee/browser-pool": "4.0.0-beta.82",
|
|
55
|
+
"@crawlee/cheerio": "4.0.0-beta.82",
|
|
56
|
+
"@crawlee/core": "4.0.0-beta.82",
|
|
57
|
+
"@crawlee/types": "4.0.0-beta.82",
|
|
58
|
+
"@crawlee/utils": "4.0.0-beta.82",
|
|
59
59
|
"cheerio": "^1.0.0",
|
|
60
60
|
"idcac-playwright": "^0.1.3",
|
|
61
61
|
"jquery": "^3.7.1",
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "eb1096f7c7743d124375ef011fbbadb19476822e"
|
|
89
89
|
}
|