@crawlee/stagehand 4.0.0-rc.1 → 4.0.0-rc.3
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 +5 -5
- package/index.js +6 -7
- package/index.mjs +2 -2
- package/internals/stagehand-browser-pool.d.ts +4 -17
- package/internals/stagehand-browser-pool.js +2 -17
- package/internals/stagehand-controller.d.ts +1 -1
- package/internals/stagehand-crawler.d.ts +2 -6
- package/internals/stagehand-crawler.js +18 -14
- package/internals/stagehand-launcher.d.ts +2 -2
- package/internals/stagehand-launcher.js +3 -3
- package/internals/stagehand-plugin.d.ts +1 -1
- package/internals/stagehand-plugin.js +3 -3
- package/internals/utils/stagehand-utils.d.ts +1 -1
- package/package.json +10 -10
package/index.d.ts
CHANGED
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
* @module @crawlee/stagehand
|
|
51
51
|
*/
|
|
52
52
|
export * from '@crawlee/browser';
|
|
53
|
-
export { StagehandCrawler, createStagehandRouter } from './internals/stagehand-crawler';
|
|
54
|
-
export { stagehandBrowserPool
|
|
55
|
-
export type { StagehandBrowserPool, StagehandBrowserPoolOptions
|
|
56
|
-
export type { StagehandOptions, StagehandPage, StagehandCrawlingContext, StagehandHook, StagehandGotoOptions, StagehandCrawlerOptions, } from './internals/stagehand-crawler';
|
|
57
|
-
export type { StagehandLaunchContext } from './internals/stagehand-launcher';
|
|
53
|
+
export { StagehandCrawler, createStagehandRouter } from './internals/stagehand-crawler.js';
|
|
54
|
+
export { stagehandBrowserPool } from './internals/stagehand-browser-pool.js';
|
|
55
|
+
export type { StagehandBrowserPool, StagehandBrowserPoolOptions } from './internals/stagehand-browser-pool.js';
|
|
56
|
+
export type { StagehandOptions, StagehandPage, StagehandCrawlingContext, StagehandHook, StagehandGotoOptions, StagehandCrawlerOptions, } from './internals/stagehand-crawler.js';
|
|
57
|
+
export type { StagehandLaunchContext } from './internals/stagehand-launcher.js';
|
|
58
58
|
export type { ActOptions, ActResult, Action, AgentConfig, ExtractOptions, ModelConfiguration, ObserveOptions, Stagehand, } from '@browserbasehq/stagehand';
|
package/index.js
CHANGED
|
@@ -51,15 +51,14 @@
|
|
|
51
51
|
* @module @crawlee/stagehand
|
|
52
52
|
*/
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.
|
|
54
|
+
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);
|
|
58
58
|
// Export main crawler class
|
|
59
|
-
var
|
|
60
|
-
Object.defineProperty(exports, "StagehandCrawler", { enumerable: true, get: function () { return
|
|
61
|
-
Object.defineProperty(exports, "createStagehandRouter", { enumerable: true, get: function () { return
|
|
59
|
+
var stagehand_crawler_js_1 = require("./internals/stagehand-crawler.js");
|
|
60
|
+
Object.defineProperty(exports, "StagehandCrawler", { enumerable: true, get: function () { return stagehand_crawler_js_1.StagehandCrawler; } });
|
|
61
|
+
Object.defineProperty(exports, "createStagehandRouter", { enumerable: true, get: function () { return stagehand_crawler_js_1.createStagehandRouter; } });
|
|
62
62
|
// Export the browser pool factories, which are how a pool with non-default options reaches the crawler
|
|
63
|
-
var
|
|
64
|
-
Object.defineProperty(exports, "stagehandBrowserPool", { enumerable: true, get: function () { return
|
|
65
|
-
Object.defineProperty(exports, "remoteStagehandBrowserPool", { enumerable: true, get: function () { return stagehand_browser_pool_1.remoteStagehandBrowserPool; } });
|
|
63
|
+
var stagehand_browser_pool_js_1 = require("./internals/stagehand-browser-pool.js");
|
|
64
|
+
Object.defineProperty(exports, "stagehandBrowserPool", { enumerable: true, get: function () { return stagehand_browser_pool_js_1.stagehandBrowserPool; } });
|
package/index.mjs
CHANGED
|
@@ -25,6 +25,7 @@ export const DATASET_ITERATORS_DEFAULT_LIMIT = mod.DATASET_ITERATORS_DEFAULT_LIM
|
|
|
25
25
|
export const DEFAULT_CURRENT_HISTORY_SECS = mod.DEFAULT_CURRENT_HISTORY_SECS;
|
|
26
26
|
export const DEFAULT_SNAPSHOT_HISTORY_SECS = mod.DEFAULT_SNAPSHOT_HISTORY_SECS;
|
|
27
27
|
export const Dataset = mod.Dataset;
|
|
28
|
+
export const DownloadStartedError = mod.DownloadStartedError;
|
|
28
29
|
export const EnqueueStrategy = mod.EnqueueStrategy;
|
|
29
30
|
export const ErrorTracker = mod.ErrorTracker;
|
|
30
31
|
export const EventLoopLoadSignal = mod.EventLoopLoadSignal;
|
|
@@ -85,7 +86,6 @@ export const applyRequestTransform = mod.applyRequestTransform;
|
|
|
85
86
|
export const assertJsonSerializable = mod.assertJsonSerializable;
|
|
86
87
|
export const bindMethodsToServiceLocator = mod.bindMethodsToServiceLocator;
|
|
87
88
|
export const browserPoolCookieToToughCookie = mod.browserPoolCookieToToughCookie;
|
|
88
|
-
export const buildEnqueueStrategyPatterns = mod.buildEnqueueStrategyPatterns;
|
|
89
89
|
export const coerceBoolean = mod.coerceBoolean;
|
|
90
90
|
export const coerceNumber = mod.coerceNumber;
|
|
91
91
|
export const constructGlobObjectsFromGlobs = mod.constructGlobObjectsFromGlobs;
|
|
@@ -123,11 +123,11 @@ export const parseValue = mod.parseValue;
|
|
|
123
123
|
export const purgeDefaultStorages = mod.purgeDefaultStorages;
|
|
124
124
|
export const rejectOperationInTransaction = mod.rejectOperationInTransaction;
|
|
125
125
|
export const remainingNavigationWindowMillis = mod.remainingNavigationWindowMillis;
|
|
126
|
-
export const remoteStagehandBrowserPool = mod.remoteStagehandBrowserPool;
|
|
127
126
|
export const resolveBaseUrlForEnqueueLinksFiltering = mod.resolveBaseUrlForEnqueueLinksFiltering;
|
|
128
127
|
export const serializeArray = mod.serializeArray;
|
|
129
128
|
export const serializeValue = mod.serializeValue;
|
|
130
129
|
export const serviceLocator = mod.serviceLocator;
|
|
130
|
+
export const skippedNavigationRequest = mod.skippedNavigationRequest;
|
|
131
131
|
export const snapshotValue = mod.snapshotValue;
|
|
132
132
|
export const stagehandBrowserPool = mod.stagehandBrowserPool;
|
|
133
133
|
export const toughCookieToBrowserPoolCookie = mod.toughCookieToBrowserPoolCookie;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Configuration } from '@crawlee/browser';
|
|
2
|
-
import type { BrowserPool, BrowserPoolHooks, BrowserPoolOptions
|
|
2
|
+
import type { BrowserPool, BrowserPoolHooks, BrowserPoolOptions } from '@crawlee/browser-pool';
|
|
3
3
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
4
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';
|
|
5
|
+
import type { StagehandOptions } from './stagehand-crawler.js';
|
|
6
|
+
import type { StagehandLaunchContext } from './stagehand-launcher.js';
|
|
7
|
+
import type { StagehandPlugin } from './stagehand-plugin.js';
|
|
8
8
|
/** A {@link BrowserPool} of Stagehand browsers, as built by {@link stagehandBrowserPool}. */
|
|
9
9
|
export type StagehandBrowserPool = BrowserPool<{
|
|
10
10
|
browserPlugins: [StagehandPlugin];
|
|
@@ -22,8 +22,6 @@ export interface StagehandBrowserPoolOptions extends Omit<BrowserPoolOptions, 'b
|
|
|
22
22
|
/** Configuration to read the browser defaults from. Defaults to the global configuration. */
|
|
23
23
|
configuration?: Configuration;
|
|
24
24
|
}
|
|
25
|
-
export interface RemoteStagehandBrowserPoolOptions extends Pick<StagehandBrowserPoolOptions, 'launchContext' | 'stagehandOptions' | 'headless' | 'configuration'>, Omit<RemoteBrowserPoolOptions, 'browserPlugins'> {
|
|
26
|
-
}
|
|
27
25
|
/**
|
|
28
26
|
* Builds a {@link BrowserPool} of Stagehand browsers to pass to a {@link StagehandCrawler} as its
|
|
29
27
|
* {@link BrowserCrawlerOptions.browserPool|`browserPool`}.
|
|
@@ -50,14 +48,3 @@ export interface RemoteStagehandBrowserPoolOptions extends Pick<StagehandBrowser
|
|
|
50
48
|
* @category Browser management
|
|
51
49
|
*/
|
|
52
50
|
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>;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stagehandBrowserPool = stagehandBrowserPool;
|
|
4
|
-
|
|
5
|
-
const stagehand_launcher_1 = require("./stagehand-launcher");
|
|
4
|
+
const stagehand_launcher_js_1 = require("./stagehand-launcher.js");
|
|
6
5
|
/**
|
|
7
6
|
* Builds a {@link BrowserPool} of Stagehand browsers to pass to a {@link StagehandCrawler} as its
|
|
8
7
|
* {@link BrowserCrawlerOptions.browserPool|`browserPool`}.
|
|
@@ -32,22 +31,8 @@ function stagehandBrowserPool(options = {}) {
|
|
|
32
31
|
const { launchContext, stagehandOptions, headless, configuration, ...poolOptions } = options;
|
|
33
32
|
return stagehandLauncher(launchContext, stagehandOptions, headless, configuration).createBrowserPool(poolOptions);
|
|
34
33
|
}
|
|
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
34
|
function stagehandLauncher(launchContext = {}, stagehandOptions = {}, headless, configuration) {
|
|
50
|
-
return new
|
|
35
|
+
return new stagehand_launcher_js_1.StagehandLauncher({
|
|
51
36
|
...launchContext,
|
|
52
37
|
stagehandOptions,
|
|
53
38
|
...(headless == null ? {} : { launchOptions: { ...launchContext.launchOptions, headless } }),
|
|
@@ -3,7 +3,7 @@ import { BrowserController } from '@crawlee/browser-pool';
|
|
|
3
3
|
import type { Cookie } from '@crawlee/types';
|
|
4
4
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
5
5
|
import type { Browser as PlaywrightBrowser, BrowserType, LaunchOptions, Page } from 'playwright';
|
|
6
|
-
import type { StagehandPlugin } from './stagehand-plugin';
|
|
6
|
+
import type { StagehandPlugin } from './stagehand-plugin.js';
|
|
7
7
|
/**
|
|
8
8
|
* StagehandController manages the lifecycle of a Stagehand-controlled browser for Crawlee's BrowserPool.
|
|
9
9
|
*
|
|
@@ -5,7 +5,7 @@ import type { Dictionary } from '@crawlee/types';
|
|
|
5
5
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
6
6
|
import type { Page, Response } from 'playwright';
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
-
import type { StagehandLaunchContext } from './stagehand-launcher';
|
|
8
|
+
import type { StagehandLaunchContext } from './stagehand-launcher.js';
|
|
9
9
|
/**
|
|
10
10
|
* Stagehand-specific configuration options.
|
|
11
11
|
*/
|
|
@@ -190,7 +190,7 @@ export type StagehandHook<UserData extends Dictionary = any> = BrowserHook<Stage
|
|
|
190
190
|
/**
|
|
191
191
|
* Options for StagehandCrawler.
|
|
192
192
|
*/
|
|
193
|
-
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> {
|
|
193
|
+
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 Omit<BrowserCrawlerOptions<StagehandPage, Response, StagehandCrawlingContext, ContextExtension, ExtendedContext, Routes, StatisticStateExtension>, 'ignoreShadowRoots' | 'ignoreIframes'> {
|
|
194
194
|
/**
|
|
195
195
|
* Stagehand-specific configuration options.
|
|
196
196
|
* These options configure the AI behavior and Browserbase integration.
|
|
@@ -349,8 +349,6 @@ export declare class StagehandCrawler<ContextExtension = Dictionary<never>, Exte
|
|
|
349
349
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
350
350
|
configuration: z.ZodOptional<z.ZodInstanceOf<import("@crawlee/browser").Configuration>>;
|
|
351
351
|
storageBackend: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
352
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
353
|
-
eventManager: z.ZodOptional<z.ZodInstanceOf<import("@crawlee/browser").EventManager>>;
|
|
354
352
|
logger: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
355
353
|
minConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
356
354
|
maxConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
@@ -410,8 +408,6 @@ export declare class StagehandCrawler<ContextExtension = Dictionary<never>, Exte
|
|
|
410
408
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
411
409
|
configuration: z.ZodOptional<z.ZodInstanceOf<import("@crawlee/browser").Configuration>>;
|
|
412
410
|
storageBackend: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
413
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
414
|
-
eventManager: z.ZodOptional<z.ZodInstanceOf<import("@crawlee/browser").EventManager>>;
|
|
415
411
|
logger: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
416
412
|
minConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
417
413
|
maxConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
@@ -5,8 +5,8 @@ exports.createStagehandRouter = createStagehandRouter;
|
|
|
5
5
|
const browser_1 = require("@crawlee/browser");
|
|
6
6
|
const internal_1 = require("@crawlee/utils/internal");
|
|
7
7
|
const zod_1 = require("zod");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const stagehand_browser_pool_js_1 = require("./stagehand-browser-pool.js");
|
|
9
|
+
const stagehand_utils_js_1 = require("./utils/stagehand-utils.js");
|
|
10
10
|
/**
|
|
11
11
|
* StagehandCrawler provides AI-powered web crawling using Browserbase's Stagehand library.
|
|
12
12
|
*
|
|
@@ -68,13 +68,18 @@ class StagehandCrawler extends browser_1.BrowserCrawler {
|
|
|
68
68
|
};
|
|
69
69
|
/** @internal */
|
|
70
70
|
static optionsSchema = zod_1.z.strictObject(StagehandCrawler.optionsShape);
|
|
71
|
+
/** Only `parseWithCheerio` reads the omitted options, and the Stagehand context has no such helper. */
|
|
72
|
+
static #constructorOptionsSchema = StagehandCrawler.optionsSchema.omit({
|
|
73
|
+
ignoreShadowRoots: true,
|
|
74
|
+
ignoreIframes: true,
|
|
75
|
+
});
|
|
71
76
|
/**
|
|
72
77
|
* Creates a new instance of StagehandCrawler.
|
|
73
78
|
*
|
|
74
79
|
* @param options - Crawler configuration options
|
|
75
80
|
*/
|
|
76
81
|
constructor(options = {}) {
|
|
77
|
-
const parsedOptions = (0, internal_1.parseArgument)(options, StagehandCrawler
|
|
82
|
+
const parsedOptions = (0, internal_1.parseArgument)(options, StagehandCrawler.#constructorOptionsSchema, 'StagehandCrawlerOptions');
|
|
78
83
|
const { stagehandOptions, launchContext, headless, configuration, ...browserCrawlerOptions } = parsedOptions;
|
|
79
84
|
if (options.browserPool) {
|
|
80
85
|
// The raw options, not the parsed ones: `launchContext` has a default, so by now it is always set.
|
|
@@ -89,20 +94,19 @@ class StagehandCrawler extends browser_1.BrowserCrawler {
|
|
|
89
94
|
configuration,
|
|
90
95
|
// The pool serves plain Playwright pages - a page only becomes a `StagehandPage` further down the
|
|
91
96
|
// pipeline, once `setUpStagehand` enhances it - so its page type is narrower than the crawler's.
|
|
92
|
-
browserPoolBuilder: (remoteBrowser) =>
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
browserPoolBuilder: (remoteBrowser) => {
|
|
98
|
+
// Stagehand manages its own browser (local or Browserbase), so a Crawlee-level remote connection
|
|
99
|
+
// would be silently ignored.
|
|
100
|
+
if (remoteBrowser) {
|
|
101
|
+
throw new Error('StagehandCrawler does not support `remoteBrowser`. Use `stagehandOptions.env: "BROWSERBASE"` instead.');
|
|
102
|
+
}
|
|
103
|
+
return (0, stagehand_browser_pool_js_1.stagehandBrowserPool)({
|
|
95
104
|
launchContext,
|
|
96
105
|
stagehandOptions,
|
|
97
106
|
headless,
|
|
98
107
|
configuration,
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
launchContext,
|
|
102
|
-
stagehandOptions,
|
|
103
|
-
headless,
|
|
104
|
-
configuration,
|
|
105
|
-
})),
|
|
108
|
+
});
|
|
109
|
+
},
|
|
106
110
|
contextPipelineBuilder: () => this.#buildContextPipeline(),
|
|
107
111
|
});
|
|
108
112
|
}
|
|
@@ -135,7 +139,7 @@ class StagehandCrawler extends browser_1.BrowserCrawler {
|
|
|
135
139
|
const stagehand = controller.getStagehand();
|
|
136
140
|
return {
|
|
137
141
|
stagehand,
|
|
138
|
-
page: (0,
|
|
142
|
+
page: (0, stagehand_utils_js_1.enhancePageWithStagehand)(crawlingContext.page, stagehand),
|
|
139
143
|
};
|
|
140
144
|
}
|
|
141
145
|
/**
|
|
@@ -3,8 +3,8 @@ import { BrowserLauncher, Configuration } from '@crawlee/browser';
|
|
|
3
3
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
4
4
|
import type { BrowserType, LaunchOptions } from 'playwright';
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
-
import type { StagehandOptions } from './stagehand-crawler';
|
|
7
|
-
import { StagehandPlugin } from './stagehand-plugin';
|
|
6
|
+
import type { StagehandOptions } from './stagehand-crawler.js';
|
|
7
|
+
import { StagehandPlugin } from './stagehand-plugin.js';
|
|
8
8
|
/**
|
|
9
9
|
* Launch context for Stagehand crawler with AI-specific options.
|
|
10
10
|
*/
|
|
@@ -4,7 +4,7 @@ exports.StagehandLauncher = void 0;
|
|
|
4
4
|
const browser_1 = require("@crawlee/browser");
|
|
5
5
|
const internal_1 = require("@crawlee/utils/internal");
|
|
6
6
|
const zod_1 = require("zod");
|
|
7
|
-
const
|
|
7
|
+
const stagehand_plugin_js_1 = require("./stagehand-plugin.js");
|
|
8
8
|
/**
|
|
9
9
|
* StagehandLauncher is based on BrowserLauncher and creates StagehandPlugin instances.
|
|
10
10
|
* It manages the lifecycle of Stagehand browsers with fingerprinting and anti-blocking features.
|
|
@@ -51,13 +51,13 @@ class StagehandLauncher extends browser_1.BrowserLauncher {
|
|
|
51
51
|
model: 'openai/gpt-4.1-mini',
|
|
52
52
|
...stagehandOptions,
|
|
53
53
|
};
|
|
54
|
-
this.Plugin =
|
|
54
|
+
this.Plugin = stagehand_plugin_js_1.StagehandPlugin;
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* Creates a new StagehandPlugin instance with resolved options.
|
|
58
58
|
*/
|
|
59
59
|
createBrowserPlugin() {
|
|
60
|
-
return new
|
|
60
|
+
return new stagehand_plugin_js_1.StagehandPlugin(this.launcher, {
|
|
61
61
|
...this.otherLaunchContextProps,
|
|
62
62
|
proxyUrl: this.proxyUrl,
|
|
63
63
|
launchOptions: this.createLaunchOptions(),
|
|
@@ -2,7 +2,7 @@ import type { BrowserController, BrowserPluginOptions, LaunchContext } from '@cr
|
|
|
2
2
|
import { BrowserPlugin } from '@crawlee/browser-pool';
|
|
3
3
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
4
4
|
import type { Browser as PlaywrightBrowser, BrowserType, LaunchOptions } from 'playwright';
|
|
5
|
-
import type { StagehandOptions } from './stagehand-crawler';
|
|
5
|
+
import type { StagehandOptions } from './stagehand-crawler.js';
|
|
6
6
|
/**
|
|
7
7
|
* Options for StagehandPlugin initialization.
|
|
8
8
|
*/
|
|
@@ -6,7 +6,7 @@ const core_1 = require("@crawlee/core");
|
|
|
6
6
|
// Stagehand is built on CDP (Chrome DevTools Protocol), which only works with Chromium-based browsers.
|
|
7
7
|
// Firefox and WebKit are not supported by Stagehand.
|
|
8
8
|
const playwright_1 = require("playwright");
|
|
9
|
-
const
|
|
9
|
+
const stagehand_controller_js_1 = require("./stagehand-controller.js");
|
|
10
10
|
/**
|
|
11
11
|
* StagehandPlugin integrates Stagehand with Crawlee's BrowserPool.
|
|
12
12
|
*
|
|
@@ -112,7 +112,7 @@ class StagehandPlugin extends browser_pool_1.BrowserPlugin {
|
|
|
112
112
|
* Creates a controller for the Stagehand browser.
|
|
113
113
|
*/
|
|
114
114
|
createController() {
|
|
115
|
-
return new
|
|
115
|
+
return new stagehand_controller_js_1.StagehandController(this, this.#stagehandInstances);
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
118
118
|
* Adds proxy configuration to launch options.
|
|
@@ -123,7 +123,7 @@ class StagehandPlugin extends browser_pool_1.BrowserPlugin {
|
|
|
123
123
|
if (proxyUrl) {
|
|
124
124
|
const url = new URL(proxyUrl);
|
|
125
125
|
launchOptions.proxy = {
|
|
126
|
-
server: url.
|
|
126
|
+
server: `${url.protocol}//${url.host}`,
|
|
127
127
|
username: decodeURIComponent(url.username),
|
|
128
128
|
password: decodeURIComponent(url.password),
|
|
129
129
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Stagehand } from '@browserbasehq/stagehand';
|
|
2
2
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
3
3
|
import type { Page } from 'playwright';
|
|
4
|
-
import type { StagehandPage } from '../stagehand-crawler';
|
|
4
|
+
import type { StagehandPage } from '../stagehand-crawler.js';
|
|
5
5
|
/**
|
|
6
6
|
* Enhances a Playwright Page with Stagehand AI methods.
|
|
7
7
|
* Adds page.act(), page.extract(), page.observe(), and page.agent() methods.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/stagehand",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.3",
|
|
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.13.0"
|
|
@@ -56,13 +56,13 @@
|
|
|
56
56
|
"access": "public"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@crawlee/browser": "4.0.0-rc.
|
|
60
|
-
"@crawlee/browser-pool": "4.0.0-rc.
|
|
61
|
-
"@crawlee/core": "4.0.0-rc.
|
|
62
|
-
"@crawlee/types": "4.0.0-rc.
|
|
63
|
-
"@crawlee/utils": "4.0.0-rc.
|
|
64
|
-
"tslib": "^2.
|
|
65
|
-
"zod": "^4.
|
|
59
|
+
"@crawlee/browser": "4.0.0-rc.3",
|
|
60
|
+
"@crawlee/browser-pool": "4.0.0-rc.3",
|
|
61
|
+
"@crawlee/core": "4.0.0-rc.3",
|
|
62
|
+
"@crawlee/types": "4.0.0-rc.3",
|
|
63
|
+
"@crawlee/utils": "4.0.0-rc.3",
|
|
64
|
+
"tslib": "^2.9.1",
|
|
65
|
+
"zod": "^4.6.7"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"@browserbasehq/stagehand": "^3.0.0",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@browserbasehq/stagehand": "3.0.7",
|
|
81
|
-
"playwright": "^1.
|
|
81
|
+
"playwright": "^1.64.1"
|
|
82
82
|
},
|
|
83
83
|
"lerna": {
|
|
84
84
|
"command": {
|
|
@@ -87,5 +87,5 @@
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
},
|
|
90
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "c8d256de99bcece26c9f675601dadaf0f2b892f2"
|
|
91
91
|
}
|