@crawlee/browser 4.0.0-beta.122 → 4.0.0-beta.124
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.
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AddRequestsBatchedResult, BasicCrawlerOptions, CrawlingContext, EnqueueLinksOptions, ErrorHandler, ExtractLinksOptions, GetUserDataFromRequest, LoadedRequest, Request, RequestHandler, RouterHandler } from '@crawlee/basic';
|
|
2
2
|
import { BasicCrawler, ContextPipeline } from '@crawlee/basic';
|
|
3
3
|
import type { BrowserController, BrowserPlugin, BrowserPoolHooks, BrowserPoolOptions, CommonPage, CrawlerRemoteBrowserOptions, InferBrowserPluginArray, LaunchContext } from '@crawlee/browser-pool';
|
|
4
|
-
import type { Awaitable,
|
|
5
|
-
import type { RobotsTxtFile } from '@crawlee/utils';
|
|
6
|
-
import type { ReadonlyDeep } from 'type-fest';
|
|
4
|
+
import type { Awaitable, Dictionary, IBrowserPool } from '@crawlee/types';
|
|
7
5
|
import { z } from 'zod';
|
|
8
6
|
import type { BrowserLaunchContext } from './browser-launcher.js';
|
|
9
7
|
interface BaseResponse {
|
|
@@ -30,10 +28,14 @@ GoToOptions extends Dictionary = Dictionary> extends CrawlingContext<UserData> {
|
|
|
30
28
|
* object (or return `{ gotoOptions: ... }`) to influence the navigation.
|
|
31
29
|
*/
|
|
32
30
|
gotoOptions: GoToOptions;
|
|
31
|
+
/**
|
|
32
|
+
* Extracts URLs from the current page, without adding them to the request queue.
|
|
33
|
+
*/
|
|
34
|
+
extractLinks: (options?: ExtractLinksOptions) => Promise<string[]>;
|
|
33
35
|
/**
|
|
34
36
|
* Helper function for extracting URLs from the current page and adding them to the request queue.
|
|
35
37
|
*/
|
|
36
|
-
enqueueLinks: (options?: EnqueueLinksOptions) => Promise<
|
|
38
|
+
enqueueLinks: (options?: EnqueueLinksOptions) => Promise<AddRequestsBatchedResult>;
|
|
37
39
|
}
|
|
38
40
|
export type BrowserHook<Context = BrowserCrawlingContext, ContextExtension = {}> = (crawlingContext: Context & ContextExtension) => Awaitable<void | Partial<Context>>;
|
|
39
41
|
export interface BrowserCrawlerOptions<Page extends CommonPage = CommonPage, Response extends BaseResponse = BaseResponse, Context extends BrowserCrawlingContext<Page, Response> = BrowserCrawlingContext<Page, Response>, ContextExtension = Dictionary<never>, ExtendedContext extends Context = Context & ContextExtension, InternalBrowserPoolOptions extends BrowserPoolOptions = BrowserPoolOptions, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<Context['request']>>, __BrowserPlugins extends BrowserPlugin[] = InferBrowserPluginArray<InternalBrowserPoolOptions['browserPlugins']>, __BrowserControllerReturn extends BrowserController = ReturnType<__BrowserPlugins[number]['createController']>, __LaunchContextReturn extends LaunchContext = ReturnType<__BrowserPlugins[number]['createLaunchContext']>> extends Omit<BasicCrawlerOptions<Context, ContextExtension, ExtendedContext>, 'requestHandler' | 'failedRequestHandler' | 'errorHandler'> {
|
|
@@ -397,26 +399,6 @@ export declare abstract class BrowserCrawler<Page extends CommonPage = CommonPag
|
|
|
397
399
|
*/
|
|
398
400
|
teardown(): Promise<void>;
|
|
399
401
|
}
|
|
400
|
-
/** @internal */
|
|
401
|
-
interface EnqueueLinksInternalOptions {
|
|
402
|
-
options?: ReadonlyDeep<Omit<EnqueueLinksOptions, 'requestManager'>> & Pick<EnqueueLinksOptions, 'requestManager'>;
|
|
403
|
-
page: CommonPage;
|
|
404
|
-
requestManager: IRequestManager;
|
|
405
|
-
robotsTxtFile?: RobotsTxtFile;
|
|
406
|
-
onSkippedRequest?: SkippedRequestCallback;
|
|
407
|
-
originalRequestUrl: string;
|
|
408
|
-
finalRequestUrl?: string;
|
|
409
|
-
}
|
|
410
|
-
/** @internal */
|
|
411
|
-
interface BoundEnqueueLinksInternalOptions {
|
|
412
|
-
enqueueLinks: BasicCrawlingContext['enqueueLinks'];
|
|
413
|
-
options?: ReadonlyDeep<Omit<EnqueueLinksOptions, 'requestManager'>> & Pick<EnqueueLinksOptions, 'requestManager'>;
|
|
414
|
-
originalRequestUrl: string;
|
|
415
|
-
finalRequestUrl?: string;
|
|
416
|
-
page: CommonPage;
|
|
417
|
-
}
|
|
418
|
-
/** @internal */
|
|
419
|
-
export declare function browserCrawlerEnqueueLinks(options: EnqueueLinksInternalOptions | BoundEnqueueLinksInternalOptions): Promise<unknown>;
|
|
420
402
|
/**
|
|
421
403
|
* Extracts URLs from a given page.
|
|
422
404
|
* @ignore
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BasicCrawler, browserPoolCookieToToughCookie, ContextPipeline, cookieStringToToughCookie,
|
|
1
|
+
import { BasicCrawler, browserPoolCookieToToughCookie, ContextPipeline, cookieStringToToughCookie, EnqueueStrategy, NavigationSkippedError, OwnedOrInjected, parseArgument, remainingNavigationWindowMillis, RequestState, RequestThrottledError, resolveBaseUrlForEnqueueLinksFiltering, schemas, SessionError, toughCookieToBrowserPoolCookie, tryAbsoluteURL, validators, } from '@crawlee/basic';
|
|
2
2
|
import { BrowserPool, RemoteBrowserPool } from '@crawlee/browser-pool';
|
|
3
3
|
import { CLOUDFLARE_RETRY_CSS_SELECTORS, RETRY_CSS_SELECTORS } from '@crawlee/utils/internal';
|
|
4
4
|
import { sleep } from '@crawlee/utils';
|
|
@@ -222,7 +222,10 @@ export class BrowserCrawler extends BasicCrawler {
|
|
|
222
222
|
session: crawlingContext.session,
|
|
223
223
|
});
|
|
224
224
|
tryCancel();
|
|
225
|
-
const
|
|
225
|
+
const addRequests = crawlingContext.addRequests;
|
|
226
|
+
const extractLinks = async (options) => {
|
|
227
|
+
return extractUrlsFromPage(page, options?.selector ?? 'a', options?.baseUrl ?? crawlingContext.request.loadedUrl ?? crawlingContext.request.url);
|
|
228
|
+
};
|
|
226
229
|
return {
|
|
227
230
|
page,
|
|
228
231
|
get response() {
|
|
@@ -231,20 +234,20 @@ export class BrowserCrawler extends BasicCrawler {
|
|
|
231
234
|
get gotoOptions() {
|
|
232
235
|
throw new Error('The `gotoOptions` property is not available until `prepareNavigation` runs.');
|
|
233
236
|
},
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
limit: await this.calculateEnqueuedRequestLimit(enqueueOptions?.limit),
|
|
239
|
-
},
|
|
240
|
-
page,
|
|
241
|
-
requestManager: await this.getRequestManager(),
|
|
242
|
-
robotsTxtFile: await this.getRobotsTxtFileForUrl(crawlingContext.request.url),
|
|
243
|
-
onSkippedRequest: this.handleSkippedRequest,
|
|
244
|
-
originalRequestUrl: crawlingContext.request.url,
|
|
237
|
+
extractLinks,
|
|
238
|
+
enqueueLinks: async (options = {}) => {
|
|
239
|
+
const baseUrl = resolveBaseUrlForEnqueueLinksFiltering({
|
|
240
|
+
enqueueStrategy: options.strategy,
|
|
245
241
|
finalRequestUrl: crawlingContext.request.loadedUrl,
|
|
246
|
-
|
|
247
|
-
|
|
242
|
+
originalRequestUrl: crawlingContext.request.url,
|
|
243
|
+
userProvidedBaseUrl: options.baseUrl,
|
|
244
|
+
});
|
|
245
|
+
const urls = await extractLinks(options);
|
|
246
|
+
return addRequests(urls, {
|
|
247
|
+
...options,
|
|
248
|
+
baseUrl,
|
|
249
|
+
strategy: options.strategy ?? EnqueueStrategy.SameHostname,
|
|
250
|
+
});
|
|
248
251
|
},
|
|
249
252
|
};
|
|
250
253
|
}
|
|
@@ -448,36 +451,6 @@ export class BrowserCrawler extends BasicCrawler {
|
|
|
448
451
|
await super.teardown();
|
|
449
452
|
}
|
|
450
453
|
}
|
|
451
|
-
/** @internal */
|
|
452
|
-
function containsEnqueueLinks(options) {
|
|
453
|
-
return !!options.enqueueLinks;
|
|
454
|
-
}
|
|
455
|
-
/** @internal */
|
|
456
|
-
export async function browserCrawlerEnqueueLinks(options) {
|
|
457
|
-
const { options: enqueueLinksOptions, finalRequestUrl, originalRequestUrl, page } = options;
|
|
458
|
-
const baseUrl = resolveBaseUrlForEnqueueLinksFiltering({
|
|
459
|
-
enqueueStrategy: enqueueLinksOptions?.strategy,
|
|
460
|
-
finalRequestUrl,
|
|
461
|
-
originalRequestUrl,
|
|
462
|
-
userProvidedBaseUrl: enqueueLinksOptions?.baseUrl,
|
|
463
|
-
});
|
|
464
|
-
const urls = await extractUrlsFromPage(page, enqueueLinksOptions?.selector ?? 'a', enqueueLinksOptions?.baseUrl ?? finalRequestUrl ?? originalRequestUrl);
|
|
465
|
-
if (containsEnqueueLinks(options)) {
|
|
466
|
-
return options.enqueueLinks({
|
|
467
|
-
urls,
|
|
468
|
-
baseUrl,
|
|
469
|
-
...enqueueLinksOptions,
|
|
470
|
-
});
|
|
471
|
-
}
|
|
472
|
-
return enqueueLinks({
|
|
473
|
-
requestManager: options.requestManager,
|
|
474
|
-
robotsTxtFile: options.robotsTxtFile,
|
|
475
|
-
onSkippedRequest: options.onSkippedRequest,
|
|
476
|
-
urls,
|
|
477
|
-
baseUrl,
|
|
478
|
-
...enqueueLinksOptions,
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
454
|
/**
|
|
482
455
|
* Extracts URLs from a given page.
|
|
483
456
|
* @ignore
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/browser",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.124",
|
|
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,10 +48,10 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@apify/timeout": "^0.4.4",
|
|
51
|
-
"@crawlee/basic": "4.0.0-beta.
|
|
52
|
-
"@crawlee/browser-pool": "4.0.0-beta.
|
|
53
|
-
"@crawlee/types": "4.0.0-beta.
|
|
54
|
-
"@crawlee/utils": "4.0.0-beta.
|
|
51
|
+
"@crawlee/basic": "4.0.0-beta.124",
|
|
52
|
+
"@crawlee/browser-pool": "4.0.0-beta.124",
|
|
53
|
+
"@crawlee/types": "4.0.0-beta.124",
|
|
54
|
+
"@crawlee/utils": "4.0.0-beta.124",
|
|
55
55
|
"tslib": "^2.8.1",
|
|
56
56
|
"type-fest": "^4.41.0",
|
|
57
57
|
"zod": "^4.4.3"
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "0694ee1b94c755b98141671baa93cc363f2bf8e3"
|
|
79
79
|
}
|