@crawlee/playwright 4.0.0-beta.238 → 4.0.0-beta.239
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.
|
@@ -83,7 +83,7 @@ export interface AdaptivePlaywrightCrawlerContext<UserData extends Dictionary =
|
|
|
83
83
|
parseWithCheerio(selector?: string, timeoutMs?: number): Promise<CheerioAPI>;
|
|
84
84
|
enqueueLinks(options?: EnqueueLinksOptions): Promise<unknown>;
|
|
85
85
|
}
|
|
86
|
-
interface AdaptiveHookContext extends Pick<AdaptivePlaywrightCrawlerContext, 'id' | 'session' | 'proxyInfo' | 'log'> {
|
|
86
|
+
interface AdaptiveHookContext extends Pick<AdaptivePlaywrightCrawlerContext, 'id' | 'session' | 'proxyInfo' | 'log' | 'extendTimeout'> {
|
|
87
87
|
page?: Page;
|
|
88
88
|
request: CrawlingRequest;
|
|
89
89
|
gotoOptions?: PlaywrightGotoOptions;
|
|
@@ -98,6 +98,12 @@ export interface AdaptiveResultContext {
|
|
|
98
98
|
request: CrawlingRequest;
|
|
99
99
|
}
|
|
100
100
|
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'> {
|
|
101
|
+
/**
|
|
102
|
+
* Timeout for the navigation phase of each attempt, in seconds, shared by the `preNavigationHooks`, the
|
|
103
|
+
* navigation and the `postNavigationHooks`. Applies to both the HTTP-only and the browser attempt. When not
|
|
104
|
+
* set, each attempt keeps its own default: 30 seconds for HTTP-only and 60 seconds for the browser.
|
|
105
|
+
*/
|
|
106
|
+
navigationTimeoutSecs?: number;
|
|
101
107
|
/**
|
|
102
108
|
* Async functions that are sequentially evaluated before the navigation. Good for setting additional cookies.
|
|
103
109
|
* The function accepts a subset of the crawling context. If you attempt to access the `page` property during HTTP-only crawling,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
2
|
import { isDeepStrictEqual } from 'node:util';
|
|
3
|
-
import { BasicCrawler, ContextPipeline, ContextPipelineInitializationError, ContextPipelineInterruptedError, RequestHandlerError, resolveBaseUrlForEnqueueLinksFiltering, Router, Statistics, } from '@crawlee/basic';
|
|
3
|
+
import { BasicCrawler, ContextPipeline, ContextPipelineInitializationError, ContextPipelineInterruptedError, navigationDeadlineKey, RequestHandlerError, resolveBaseUrlForEnqueueLinksFiltering, Router, Statistics, } from '@crawlee/basic';
|
|
4
4
|
import { extractUrlsFromPage } from '@crawlee/browser';
|
|
5
5
|
import { CheerioCrawler } from '@crawlee/cheerio';
|
|
6
6
|
import { ResponseWithUrl } from '@crawlee/http-client';
|
|
@@ -89,7 +89,7 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
|
|
|
89
89
|
*/
|
|
90
90
|
#shutDown = false;
|
|
91
91
|
constructor(options = {}) {
|
|
92
|
-
const { requestHandler, renderingTypeDetectionRatio = 0.1, renderingTypePredictor, resultChecker, shouldPropagateError, resultComparator, statistics, requestHandlerTimeoutSecs = 60, errorHandler, failedRequestHandler, preNavigationHooks = [], postNavigationHooks = [], extendContext, transactionalStorage, launchContext, headless, browserPool, remoteBrowser, ...rest } = options;
|
|
92
|
+
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;
|
|
93
93
|
// The user's value is replaced by `false` in the `super` call below — validate it separately,
|
|
94
94
|
// wrapped in an object so the error still names the field.
|
|
95
95
|
parseArgument({ transactionalStorage }, z.object({ transactionalStorage: BasicCrawler.optionsShape.transactionalStorage }), 'AdaptivePlaywrightCrawlerOptions');
|
|
@@ -170,6 +170,7 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
|
|
|
170
170
|
preNavigationHooks,
|
|
171
171
|
postNavigationHooks,
|
|
172
172
|
extendContext,
|
|
173
|
+
navigationTimeoutSecs,
|
|
173
174
|
});
|
|
174
175
|
const browserCrawler = new PlaywrightCrawler({
|
|
175
176
|
...rest,
|
|
@@ -177,6 +178,7 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
|
|
|
177
178
|
preNavigationHooks: preNavigationHooks,
|
|
178
179
|
postNavigationHooks: postNavigationHooks,
|
|
179
180
|
extendContext,
|
|
181
|
+
navigationTimeoutSecs,
|
|
180
182
|
launchContext,
|
|
181
183
|
headless,
|
|
182
184
|
browserPool,
|
|
@@ -276,12 +278,20 @@ export class AdaptivePlaywrightCrawler extends BasicCrawler {
|
|
|
276
278
|
transactions.push(transaction);
|
|
277
279
|
const logs = [];
|
|
278
280
|
const deferredCleanup = [];
|
|
281
|
+
const subCrawlerContext = Object.defineProperties({}, Object.getOwnPropertyDescriptors(context));
|
|
279
282
|
const attemptBoundContextHelpers = {
|
|
280
283
|
useState: useStateFunction,
|
|
281
284
|
log: this.#createLogProxy(context.log, logs),
|
|
282
285
|
registerDeferredCleanup: (cleanup) => deferredCleanup.push(cleanup),
|
|
286
|
+
// The sub-crawler pipeline keeps this attempt's navigation deadline on `subCrawlerContext`, but the
|
|
287
|
+
// outer `extendTimeout` only pushes the deadline it finds on `context`, so push this one as well.
|
|
288
|
+
extendTimeout: (secs) => {
|
|
289
|
+
context.extendTimeout(secs);
|
|
290
|
+
if (subCrawlerContext[navigationDeadlineKey] !== undefined) {
|
|
291
|
+
subCrawlerContext[navigationDeadlineKey] += secs * 1000;
|
|
292
|
+
}
|
|
293
|
+
},
|
|
283
294
|
};
|
|
284
|
-
const subCrawlerContext = Object.defineProperties({}, Object.getOwnPropertyDescriptors(context));
|
|
285
295
|
// Mark attempt-bound helpers as non-configurable so they survive the sub-crawler context pipeline
|
|
286
296
|
// (which would otherwise override them with the sub-crawler's own versions, losing the binding).
|
|
287
297
|
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(attemptBoundContextHelpers))) {
|
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.239",
|
|
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.239",
|
|
53
|
+
"@crawlee/browser": "4.0.0-beta.239",
|
|
54
|
+
"@crawlee/browser-pool": "4.0.0-beta.239",
|
|
55
|
+
"@crawlee/cheerio": "4.0.0-beta.239",
|
|
56
|
+
"@crawlee/core": "4.0.0-beta.239",
|
|
57
|
+
"@crawlee/http-client": "4.0.0-beta.239",
|
|
58
|
+
"@crawlee/types": "4.0.0-beta.239",
|
|
59
|
+
"@crawlee/utils": "4.0.0-beta.239",
|
|
60
60
|
"cheerio": "^1.0.0",
|
|
61
61
|
"domhandler": "^6.0.0",
|
|
62
62
|
"jquery": "^3.7.1",
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "5fadaae0607c497eeffd0029fb17955f69d2ed46"
|
|
85
85
|
}
|