@crawlee/stagehand 4.0.0-beta.124 → 4.0.0-beta.126
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/index.d.ts +2 -0
- package/index.js +5 -1
- package/index.mjs +4 -0
- package/internals/stagehand-browser-pool.d.ts +63 -0
- package/internals/stagehand-browser-pool.js +55 -0
- package/internals/stagehand-crawler.d.ts +12 -12
- package/internals/stagehand-crawler.js +28 -14
- package/package.json +7 -7
package/index.d.ts
CHANGED
|
@@ -51,6 +51,8 @@
|
|
|
51
51
|
*/
|
|
52
52
|
export * from '@crawlee/browser';
|
|
53
53
|
export { StagehandCrawler, createStagehandRouter } from './internals/stagehand-crawler';
|
|
54
|
+
export { stagehandBrowserPool, remoteStagehandBrowserPool } from './internals/stagehand-browser-pool';
|
|
55
|
+
export type { StagehandBrowserPool, StagehandBrowserPoolOptions, RemoteStagehandBrowserPoolOptions, } from './internals/stagehand-browser-pool';
|
|
54
56
|
export type { StagehandOptions, StagehandPage, StagehandCrawlingContext, StagehandHook, StagehandRequestHandler, StagehandGotoOptions, StagehandCrawlerOptions, } from './internals/stagehand-crawler';
|
|
55
57
|
export type { StagehandLaunchContext } from './internals/stagehand-launcher';
|
|
56
58
|
export * as stagehandUtils from './internals/utils/stagehand-utils';
|
package/index.js
CHANGED
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
* @module @crawlee/stagehand
|
|
52
52
|
*/
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.stagehandUtils = exports.createStagehandRouter = exports.StagehandCrawler = void 0;
|
|
54
|
+
exports.stagehandUtils = exports.remoteStagehandBrowserPool = exports.stagehandBrowserPool = exports.createStagehandRouter = exports.StagehandCrawler = void 0;
|
|
55
55
|
const tslib_1 = require("tslib");
|
|
56
56
|
// Re-export everything from @crawlee/browser for convenience
|
|
57
57
|
tslib_1.__exportStar(require("@crawlee/browser"), exports);
|
|
@@ -59,5 +59,9 @@ tslib_1.__exportStar(require("@crawlee/browser"), exports);
|
|
|
59
59
|
var stagehand_crawler_1 = require("./internals/stagehand-crawler");
|
|
60
60
|
Object.defineProperty(exports, "StagehandCrawler", { enumerable: true, get: function () { return stagehand_crawler_1.StagehandCrawler; } });
|
|
61
61
|
Object.defineProperty(exports, "createStagehandRouter", { enumerable: true, get: function () { return stagehand_crawler_1.createStagehandRouter; } });
|
|
62
|
+
// Export the browser pool factories, which are how a pool with non-default options reaches the crawler
|
|
63
|
+
var stagehand_browser_pool_1 = require("./internals/stagehand-browser-pool");
|
|
64
|
+
Object.defineProperty(exports, "stagehandBrowserPool", { enumerable: true, get: function () { return stagehand_browser_pool_1.stagehandBrowserPool; } });
|
|
65
|
+
Object.defineProperty(exports, "remoteStagehandBrowserPool", { enumerable: true, get: function () { return stagehand_browser_pool_1.remoteStagehandBrowserPool; } });
|
|
62
66
|
// Export utilities as namespace
|
|
63
67
|
exports.stagehandUtils = tslib_1.__importStar(require("./internals/utils/stagehand-utils"));
|
package/index.mjs
CHANGED
|
@@ -83,6 +83,7 @@ export const SystemStatus = mod.SystemStatus;
|
|
|
83
83
|
export const ThrottlingRequestManager = mod.ThrottlingRequestManager;
|
|
84
84
|
export const activeStorageTransaction = mod.activeStorageTransaction;
|
|
85
85
|
export const applyRequestTransform = mod.applyRequestTransform;
|
|
86
|
+
export const assertBrowserPoolNotConfigured = mod.assertBrowserPoolNotConfigured;
|
|
86
87
|
export const assertJsonSerializable = mod.assertJsonSerializable;
|
|
87
88
|
export const bindMethodsToServiceLocator = mod.bindMethodsToServiceLocator;
|
|
88
89
|
export const browserPoolCookieToToughCookie = mod.browserPoolCookieToToughCookie;
|
|
@@ -92,6 +93,7 @@ export const coerceNumber = mod.coerceNumber;
|
|
|
92
93
|
export const constructGlobObjectsFromGlobs = mod.constructGlobObjectsFromGlobs;
|
|
93
94
|
export const constructRegExpObjectsFromRegExps = mod.constructRegExpObjectsFromRegExps;
|
|
94
95
|
export const constructUrlPatternObjects = mod.constructUrlPatternObjects;
|
|
96
|
+
export const convertStateSync = mod.convertStateSync;
|
|
95
97
|
export const cookieStringToToughCookie = mod.cookieStringToToughCookie;
|
|
96
98
|
export const crawleeConfigFields = mod.crawleeConfigFields;
|
|
97
99
|
export const createBasicRouter = mod.createBasicRouter;
|
|
@@ -123,6 +125,7 @@ export const parseValue = mod.parseValue;
|
|
|
123
125
|
export const purgeDefaultStorages = mod.purgeDefaultStorages;
|
|
124
126
|
export const rejectOperationInTransaction = mod.rejectOperationInTransaction;
|
|
125
127
|
export const remainingNavigationWindowMillis = mod.remainingNavigationWindowMillis;
|
|
128
|
+
export const remoteStagehandBrowserPool = mod.remoteStagehandBrowserPool;
|
|
126
129
|
export const resolveBaseUrlForEnqueueLinksFiltering = mod.resolveBaseUrlForEnqueueLinksFiltering;
|
|
127
130
|
export const resolveStorageIdentifier = mod.resolveStorageIdentifier;
|
|
128
131
|
export const schemas = mod.schemas;
|
|
@@ -130,6 +133,7 @@ export const serializeArray = mod.serializeArray;
|
|
|
130
133
|
export const serializeValue = mod.serializeValue;
|
|
131
134
|
export const serviceLocator = mod.serviceLocator;
|
|
132
135
|
export const snapshotValue = mod.snapshotValue;
|
|
136
|
+
export const stagehandBrowserPool = mod.stagehandBrowserPool;
|
|
133
137
|
export const stagehandUtils = mod.stagehandUtils;
|
|
134
138
|
export const supportsDomainThrottling = mod.supportsDomainThrottling;
|
|
135
139
|
export const toughCookieToBrowserPoolCookie = mod.toughCookieToBrowserPoolCookie;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Configuration } from '@crawlee/browser';
|
|
2
|
+
import type { BrowserPool, BrowserPoolHooks, BrowserPoolOptions, RemoteBrowserPool, RemoteBrowserPoolOptions } from '@crawlee/browser-pool';
|
|
3
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
4
|
+
import type { Page } from 'playwright';
|
|
5
|
+
import type { StagehandOptions } from './stagehand-crawler';
|
|
6
|
+
import type { StagehandLaunchContext } from './stagehand-launcher';
|
|
7
|
+
import type { StagehandPlugin } from './stagehand-plugin';
|
|
8
|
+
/** A {@link BrowserPool} of Stagehand browsers, as built by {@link stagehandBrowserPool}. */
|
|
9
|
+
export type StagehandBrowserPool = BrowserPool<{
|
|
10
|
+
browserPlugins: [StagehandPlugin];
|
|
11
|
+
}, [StagehandPlugin]>;
|
|
12
|
+
export interface StagehandBrowserPoolOptions extends Omit<BrowserPoolOptions, 'browserPlugins'>, BrowserPoolHooks<ReturnType<StagehandPlugin['createController']>, ReturnType<StagehandPlugin['createLaunchContext']>, Page> {
|
|
13
|
+
/** How to launch the browser: which Playwright browser type, proxy, user data dir, ... */
|
|
14
|
+
launchContext?: StagehandLaunchContext;
|
|
15
|
+
/** Stagehand configuration for the AI behavior and Browserbase integration. */
|
|
16
|
+
stagehandOptions?: StagehandOptions;
|
|
17
|
+
/**
|
|
18
|
+
* Whether to run the browser in headless mode. Shorthand for `launchContext.launchOptions.headless`.
|
|
19
|
+
* Defaults to `true`, and can also be set via {@link Configuration}.
|
|
20
|
+
*/
|
|
21
|
+
headless?: boolean;
|
|
22
|
+
/** Configuration to read the browser defaults from. Defaults to the global configuration. */
|
|
23
|
+
configuration?: Configuration;
|
|
24
|
+
}
|
|
25
|
+
export interface RemoteStagehandBrowserPoolOptions extends Pick<StagehandBrowserPoolOptions, 'launchContext' | 'stagehandOptions' | 'headless' | 'configuration'>, Omit<RemoteBrowserPoolOptions, 'browserPlugins'> {
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Builds a {@link BrowserPool} of Stagehand browsers to pass to a {@link StagehandCrawler} as its
|
|
29
|
+
* {@link BrowserCrawlerOptions.browserPool|`browserPool`}.
|
|
30
|
+
*
|
|
31
|
+
* It accepts every {@link BrowserPoolOptions|`BrowserPool` option} plus the crawler's own `launchContext`,
|
|
32
|
+
* `stagehandOptions` and `headless`, and derives the browser plugin from them - so a pool built here always
|
|
33
|
+
* matches the crawler it is given to, and configuring one never means assembling a {@link StagehandPlugin}
|
|
34
|
+
* by hand.
|
|
35
|
+
*
|
|
36
|
+
* **Example usage:**
|
|
37
|
+
*
|
|
38
|
+
* ```javascript
|
|
39
|
+
* const crawler = new StagehandCrawler({
|
|
40
|
+
* browserPool: stagehandBrowserPool({
|
|
41
|
+
* maxOpenPagesPerBrowser: 1,
|
|
42
|
+
* stagehandOptions: { env: 'LOCAL', model: 'openai/gpt-4.1-mini' },
|
|
43
|
+
* }),
|
|
44
|
+
* requestHandler: async ({ page }) => { ... },
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* The returned pool is *not* torn down by the crawler, which is what makes it shareable between crawlers.
|
|
49
|
+
*
|
|
50
|
+
* @category Browser management
|
|
51
|
+
*/
|
|
52
|
+
export declare function stagehandBrowserPool(options?: StagehandBrowserPoolOptions): StagehandBrowserPool;
|
|
53
|
+
/**
|
|
54
|
+
* The {@link RemoteBrowserPool} counterpart of {@link stagehandBrowserPool}: connects to a remote browser
|
|
55
|
+
* service with a Stagehand plugin derived from `launchContext` and `stagehandOptions`.
|
|
56
|
+
*
|
|
57
|
+
* A {@link StagehandCrawler} accepts the same connection details directly via
|
|
58
|
+
* {@link BrowserCrawlerOptions.remoteBrowser|`remoteBrowser`}; reach for this factory when you also need to
|
|
59
|
+
* tune the wrapping pool, or to share one remote pool between crawlers.
|
|
60
|
+
*
|
|
61
|
+
* @category Browser management
|
|
62
|
+
*/
|
|
63
|
+
export declare function remoteStagehandBrowserPool(options: RemoteStagehandBrowserPoolOptions): RemoteBrowserPool<Page>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stagehandBrowserPool = stagehandBrowserPool;
|
|
4
|
+
exports.remoteStagehandBrowserPool = remoteStagehandBrowserPool;
|
|
5
|
+
const stagehand_launcher_1 = require("./stagehand-launcher");
|
|
6
|
+
/**
|
|
7
|
+
* Builds a {@link BrowserPool} of Stagehand browsers to pass to a {@link StagehandCrawler} as its
|
|
8
|
+
* {@link BrowserCrawlerOptions.browserPool|`browserPool`}.
|
|
9
|
+
*
|
|
10
|
+
* It accepts every {@link BrowserPoolOptions|`BrowserPool` option} plus the crawler's own `launchContext`,
|
|
11
|
+
* `stagehandOptions` and `headless`, and derives the browser plugin from them - so a pool built here always
|
|
12
|
+
* matches the crawler it is given to, and configuring one never means assembling a {@link StagehandPlugin}
|
|
13
|
+
* by hand.
|
|
14
|
+
*
|
|
15
|
+
* **Example usage:**
|
|
16
|
+
*
|
|
17
|
+
* ```javascript
|
|
18
|
+
* const crawler = new StagehandCrawler({
|
|
19
|
+
* browserPool: stagehandBrowserPool({
|
|
20
|
+
* maxOpenPagesPerBrowser: 1,
|
|
21
|
+
* stagehandOptions: { env: 'LOCAL', model: 'openai/gpt-4.1-mini' },
|
|
22
|
+
* }),
|
|
23
|
+
* requestHandler: async ({ page }) => { ... },
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* The returned pool is *not* torn down by the crawler, which is what makes it shareable between crawlers.
|
|
28
|
+
*
|
|
29
|
+
* @category Browser management
|
|
30
|
+
*/
|
|
31
|
+
function stagehandBrowserPool(options = {}) {
|
|
32
|
+
const { launchContext, stagehandOptions, headless, configuration, ...poolOptions } = options;
|
|
33
|
+
return stagehandLauncher(launchContext, stagehandOptions, headless, configuration).createBrowserPool(poolOptions);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The {@link RemoteBrowserPool} counterpart of {@link stagehandBrowserPool}: connects to a remote browser
|
|
37
|
+
* service with a Stagehand plugin derived from `launchContext` and `stagehandOptions`.
|
|
38
|
+
*
|
|
39
|
+
* A {@link StagehandCrawler} accepts the same connection details directly via
|
|
40
|
+
* {@link BrowserCrawlerOptions.remoteBrowser|`remoteBrowser`}; reach for this factory when you also need to
|
|
41
|
+
* tune the wrapping pool, or to share one remote pool between crawlers.
|
|
42
|
+
*
|
|
43
|
+
* @category Browser management
|
|
44
|
+
*/
|
|
45
|
+
function remoteStagehandBrowserPool(options) {
|
|
46
|
+
const { launchContext, stagehandOptions, headless, configuration, ...remoteOptions } = options;
|
|
47
|
+
return stagehandLauncher(launchContext, stagehandOptions, headless, configuration).createRemoteBrowserPool(remoteOptions);
|
|
48
|
+
}
|
|
49
|
+
function stagehandLauncher(launchContext = {}, stagehandOptions = {}, headless, configuration) {
|
|
50
|
+
return new stagehand_launcher_1.StagehandLauncher({
|
|
51
|
+
...launchContext,
|
|
52
|
+
stagehandOptions,
|
|
53
|
+
...(headless == null ? {} : { launchOptions: { ...launchContext.launchOptions, headless } }),
|
|
54
|
+
}, configuration);
|
|
55
|
+
}
|
|
@@ -6,7 +6,6 @@ import type { Dictionary } from '@crawlee/types';
|
|
|
6
6
|
import type { LaunchOptions, Page, Response } from 'playwright';
|
|
7
7
|
import { z } from 'zod';
|
|
8
8
|
import type { StagehandLaunchContext } from './stagehand-launcher';
|
|
9
|
-
import type { StagehandPlugin } from './stagehand-plugin';
|
|
10
9
|
/**
|
|
11
10
|
* Stagehand-specific configuration options.
|
|
12
11
|
*/
|
|
@@ -196,9 +195,7 @@ export interface StagehandRequestHandler extends RequestHandler<LoadedContext<St
|
|
|
196
195
|
/**
|
|
197
196
|
* Options for StagehandCrawler.
|
|
198
197
|
*/
|
|
199
|
-
export interface StagehandCrawlerOptions<ContextExtension = Dictionary<never>, ExtendedContext extends StagehandCrawlingContext = StagehandCrawlingContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<StagehandCrawlingContext['request']
|
|
200
|
-
browserPlugins: [StagehandPlugin];
|
|
201
|
-
}, Routes> {
|
|
198
|
+
export interface StagehandCrawlerOptions<ContextExtension = Dictionary<never>, ExtendedContext extends StagehandCrawlingContext = StagehandCrawlingContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<StagehandCrawlingContext['request']>>, StatisticStateExtension extends object = {}> extends BrowserCrawlerOptions<StagehandPage, Response, StagehandCrawlingContext, ContextExtension, ExtendedContext, Routes, StatisticStateExtension> {
|
|
202
199
|
/**
|
|
203
200
|
* Stagehand-specific configuration options.
|
|
204
201
|
* These options configure the AI behavior and Browserbase integration.
|
|
@@ -208,6 +205,11 @@ export interface StagehandCrawlerOptions<ContextExtension = Dictionary<never>, E
|
|
|
208
205
|
* Launch context with Stagehand-specific options.
|
|
209
206
|
*/
|
|
210
207
|
launchContext?: StagehandLaunchContext;
|
|
208
|
+
/**
|
|
209
|
+
* Whether to run browser in headless mode. Defaults to `true`.
|
|
210
|
+
* Can be also set via {@link Configuration}.
|
|
211
|
+
*/
|
|
212
|
+
headless?: boolean;
|
|
211
213
|
/**
|
|
212
214
|
* Function that is called to process each request.
|
|
213
215
|
*
|
|
@@ -311,18 +313,16 @@ export interface StagehandCrawlerOptions<ContextExtension = Dictionary<never>, E
|
|
|
311
313
|
* await crawler.run(['https://example.com']);
|
|
312
314
|
* ```
|
|
313
315
|
*/
|
|
314
|
-
export declare class StagehandCrawler<ContextExtension = Dictionary<never>, ExtendedContext extends StagehandCrawlingContext = StagehandCrawlingContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<StagehandCrawlingContext['request']
|
|
315
|
-
browserPlugins: [StagehandPlugin];
|
|
316
|
-
}, LaunchOptions, StagehandCrawlingContext, ContextExtension, ExtendedContext, Routes> {
|
|
316
|
+
export declare class StagehandCrawler<ContextExtension = Dictionary<never>, ExtendedContext extends StagehandCrawlingContext = StagehandCrawlingContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<StagehandCrawlingContext['request']>>, StatisticStateExtension extends object = {}> extends BrowserCrawler<StagehandPage, Response, LaunchOptions, StagehandCrawlingContext, ContextExtension, ExtendedContext, Routes, StatisticStateExtension> {
|
|
317
317
|
protected static optionsShape: {
|
|
318
318
|
stagehandOptions: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
319
|
-
|
|
319
|
+
headless: z.ZodOptional<z.ZodBoolean>;
|
|
320
320
|
navigationTimeoutSecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
321
321
|
preNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
322
322
|
postNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
323
323
|
launchContext: z.ZodDefault<z.ZodCustom<Dictionary, Dictionary>>;
|
|
324
|
-
headless: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>;
|
|
325
324
|
browserPool: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
325
|
+
browserPoolBuilder: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
326
326
|
remoteBrowser: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
327
327
|
saveResponseCookies: z.ZodDefault<z.ZodBoolean>;
|
|
328
328
|
proxyConfiguration: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
@@ -375,13 +375,13 @@ export declare class StagehandCrawler<ContextExtension = Dictionary<never>, Exte
|
|
|
375
375
|
};
|
|
376
376
|
protected static optionsSchema: z.ZodObject<{
|
|
377
377
|
stagehandOptions: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
378
|
-
|
|
378
|
+
headless: z.ZodOptional<z.ZodBoolean>;
|
|
379
379
|
navigationTimeoutSecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
380
380
|
preNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
381
381
|
postNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
382
382
|
launchContext: z.ZodDefault<z.ZodCustom<Dictionary, Dictionary>>;
|
|
383
|
-
headless: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>;
|
|
384
383
|
browserPool: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
384
|
+
browserPoolBuilder: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
385
385
|
remoteBrowser: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
386
386
|
saveResponseCookies: z.ZodDefault<z.ZodBoolean>;
|
|
387
387
|
proxyConfiguration: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
@@ -437,7 +437,7 @@ export declare class StagehandCrawler<ContextExtension = Dictionary<never>, Exte
|
|
|
437
437
|
*
|
|
438
438
|
* @param options - Crawler configuration options
|
|
439
439
|
*/
|
|
440
|
-
constructor(options?: StagehandCrawlerOptions<ContextExtension, ExtendedContext, Routes>);
|
|
440
|
+
constructor(options?: StagehandCrawlerOptions<ContextExtension, ExtendedContext, Routes, StatisticStateExtension>);
|
|
441
441
|
protected buildContextPipeline(): ContextPipeline<CrawlingContext, StagehandCrawlingContext>;
|
|
442
442
|
/**
|
|
443
443
|
* Resolves the {@link StagehandController} that owns the given page, or
|
|
@@ -4,7 +4,7 @@ exports.StagehandCrawler = void 0;
|
|
|
4
4
|
exports.createStagehandRouter = createStagehandRouter;
|
|
5
5
|
const browser_1 = require("@crawlee/browser");
|
|
6
6
|
const zod_1 = require("zod");
|
|
7
|
-
const
|
|
7
|
+
const stagehand_browser_pool_1 = require("./stagehand-browser-pool");
|
|
8
8
|
const stagehand_utils_1 = require("./utils/stagehand-utils");
|
|
9
9
|
/**
|
|
10
10
|
* StagehandCrawler provides AI-powered web crawling using Browserbase's Stagehand library.
|
|
@@ -59,7 +59,7 @@ class StagehandCrawler extends browser_1.BrowserCrawler {
|
|
|
59
59
|
static optionsShape = {
|
|
60
60
|
...browser_1.BrowserCrawler.optionsShape,
|
|
61
61
|
stagehandOptions: browser_1.schemas.anyObject.optional(),
|
|
62
|
-
|
|
62
|
+
headless: zod_1.z.boolean().optional(),
|
|
63
63
|
};
|
|
64
64
|
static optionsSchema = zod_1.z.strictObject(StagehandCrawler.optionsShape);
|
|
65
65
|
/**
|
|
@@ -69,21 +69,35 @@ class StagehandCrawler extends browser_1.BrowserCrawler {
|
|
|
69
69
|
*/
|
|
70
70
|
constructor(options = {}) {
|
|
71
71
|
const parsedOptions = (0, browser_1.parseArgument)(options, StagehandCrawler.optionsSchema, 'StagehandCrawlerOptions');
|
|
72
|
-
const { stagehandOptions
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
browserPoolOptions.browserPlugins = [launcher.createBrowserPlugin()];
|
|
82
|
-
// Initialize BrowserCrawler with Stagehand plugin and fingerprinting enabled
|
|
72
|
+
const { stagehandOptions, launchContext, headless, configuration, contextPipelineBuilder, ...browserCrawlerOptions } = parsedOptions;
|
|
73
|
+
if (options.browserPool) {
|
|
74
|
+
// The raw options, not the parsed ones: `launchContext` has a default, so by now it is always set.
|
|
75
|
+
(0, browser_1.assertBrowserPoolNotConfigured)(new.target.name, {
|
|
76
|
+
launchContext: options.launchContext,
|
|
77
|
+
stagehandOptions: options.stagehandOptions,
|
|
78
|
+
headless: options.headless,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
83
81
|
super({
|
|
84
82
|
...browserCrawlerOptions,
|
|
85
83
|
launchContext,
|
|
86
|
-
|
|
84
|
+
configuration,
|
|
85
|
+
// The pool serves plain Playwright pages - a page only becomes a `StagehandPage` further down the
|
|
86
|
+
// pipeline, once `setUpStagehand` enhances it - so its page type is narrower than the crawler's.
|
|
87
|
+
browserPoolBuilder: (remoteBrowser) => (remoteBrowser
|
|
88
|
+
? (0, stagehand_browser_pool_1.remoteStagehandBrowserPool)({
|
|
89
|
+
...remoteBrowser,
|
|
90
|
+
launchContext,
|
|
91
|
+
stagehandOptions,
|
|
92
|
+
headless,
|
|
93
|
+
configuration,
|
|
94
|
+
})
|
|
95
|
+
: (0, stagehand_browser_pool_1.stagehandBrowserPool)({
|
|
96
|
+
launchContext,
|
|
97
|
+
stagehandOptions,
|
|
98
|
+
headless,
|
|
99
|
+
configuration,
|
|
100
|
+
})),
|
|
87
101
|
contextPipelineBuilder: contextPipelineBuilder ?? (() => this.buildContextPipeline()),
|
|
88
102
|
});
|
|
89
103
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/stagehand",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.126",
|
|
4
4
|
"description": "AI-powered web crawling with Stagehand integration for Crawlee - enables natural language browser automation with act(), extract(), and observe() methods.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.0.0"
|
|
@@ -57,11 +57,11 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@apify/timeout": "^0.4.4",
|
|
60
|
-
"@crawlee/browser": "4.0.0-beta.
|
|
61
|
-
"@crawlee/browser-pool": "4.0.0-beta.
|
|
62
|
-
"@crawlee/core": "4.0.0-beta.
|
|
63
|
-
"@crawlee/types": "4.0.0-beta.
|
|
64
|
-
"@crawlee/utils": "4.0.0-beta.
|
|
60
|
+
"@crawlee/browser": "4.0.0-beta.126",
|
|
61
|
+
"@crawlee/browser-pool": "4.0.0-beta.126",
|
|
62
|
+
"@crawlee/core": "4.0.0-beta.126",
|
|
63
|
+
"@crawlee/types": "4.0.0-beta.126",
|
|
64
|
+
"@crawlee/utils": "4.0.0-beta.126",
|
|
65
65
|
"tslib": "^2.8.1",
|
|
66
66
|
"zod": "^4.4.3"
|
|
67
67
|
},
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
},
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "5f0a8c1a43d4587f8640881fc55836a23e1c4f30"
|
|
92
92
|
}
|