@crawlee/playwright 4.0.0-beta.252 → 4.0.0-beta.253
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.
|
@@ -186,8 +186,26 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
|
|
|
186
186
|
});
|
|
187
187
|
this.#staticCrawler = staticCrawler;
|
|
188
188
|
this.#browserCrawler = browserCrawler;
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
// Each attempt needs its own deferred cleanups, and they must share the attempt's cleanup stack: resources the
|
|
190
|
+
// pipeline defers releasing (the page) have to outlive the user's cleanups, which may still use them.
|
|
191
|
+
const deferredCleanup = ContextPipeline.create().compose((_context, onCleanup) => ({
|
|
192
|
+
registerDeferredCleanup: (cleanup) => {
|
|
193
|
+
onCleanup(async () => {
|
|
194
|
+
try {
|
|
195
|
+
await cleanup();
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
this.log.debug('Error in deferred cleanup', { error });
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
}));
|
|
203
|
+
this.#staticContextPipeline = deferredCleanup
|
|
204
|
+
.chain(staticCrawler.contextPipeline)
|
|
205
|
+
.compose(this.#adaptCheerioContext.bind(this));
|
|
206
|
+
this.#browserContextPipeline = deferredCleanup
|
|
207
|
+
.chain(browserCrawler.contextPipeline)
|
|
208
|
+
.compose(this.#adaptPlaywrightContext.bind(this));
|
|
191
209
|
}
|
|
192
210
|
async init() {
|
|
193
211
|
// A crawler can be run again after a teardown.
|
|
@@ -285,7 +303,6 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
|
|
|
285
303
|
});
|
|
286
304
|
transactions.push(transaction);
|
|
287
305
|
const logs = [];
|
|
288
|
-
const deferredCleanup = [];
|
|
289
306
|
const contextModifications = {
|
|
290
307
|
request: new MutationJournal(),
|
|
291
308
|
state: new MutationJournal(),
|
|
@@ -295,7 +312,6 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
|
|
|
295
312
|
request: contextModifications.request.track(request),
|
|
296
313
|
useState: async (defaultValue) => contextModifications.state.track(await useStateFunction(defaultValue)),
|
|
297
314
|
log: this.#createLogProxy(context.log, logs),
|
|
298
|
-
registerDeferredCleanup: (cleanup) => deferredCleanup.push(cleanup),
|
|
299
315
|
// The sub-crawler pipeline keeps this attempt's navigation deadline on `subCrawlerContext`, but the
|
|
300
316
|
// outer `extendTimeout` only pushes the deadline it finds on `context`, so push this one as well.
|
|
301
317
|
extendTimeout: (secs) => {
|
|
@@ -333,9 +349,6 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
|
|
|
333
349
|
catch (error) {
|
|
334
350
|
return { ok: false, error, transaction, contextModifications, logs };
|
|
335
351
|
}
|
|
336
|
-
finally {
|
|
337
|
-
await Promise.all(deferredCleanup.map((cleanup) => cleanup()));
|
|
338
|
-
}
|
|
339
352
|
}
|
|
340
353
|
async runRequestHandler(crawlingContext) {
|
|
341
354
|
const renderingTypePrediction = await this.#renderingTypePredictor.value.predict(crawlingContext.request);
|
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.253",
|
|
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,14 +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.
|
|
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/http-client": "4.0.0-beta.
|
|
58
|
-
"@crawlee/types": "4.0.0-beta.
|
|
59
|
-
"@crawlee/utils": "4.0.0-beta.
|
|
52
|
+
"@crawlee/basic": "4.0.0-beta.253",
|
|
53
|
+
"@crawlee/browser": "4.0.0-beta.253",
|
|
54
|
+
"@crawlee/browser-pool": "4.0.0-beta.253",
|
|
55
|
+
"@crawlee/cheerio": "4.0.0-beta.253",
|
|
56
|
+
"@crawlee/core": "4.0.0-beta.253",
|
|
57
|
+
"@crawlee/http-client": "4.0.0-beta.253",
|
|
58
|
+
"@crawlee/types": "4.0.0-beta.253",
|
|
59
|
+
"@crawlee/utils": "4.0.0-beta.253",
|
|
60
60
|
"cheerio": "^1.2.0",
|
|
61
61
|
"domhandler": "^6.0.1",
|
|
62
62
|
"jquery": "^3.7.1",
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "f93aa3970468c422d9626db0d21175e8a39fdfed"
|
|
85
85
|
}
|