@crawlee/stagehand 3.15.4-beta.39

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/LICENSE.md ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2018 Apify Technologies s.r.o.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,153 @@
1
+ <h1 align="center">
2
+ <a href="https://crawlee.dev">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-dark.svg?sanitize=true">
5
+ <img alt="Crawlee" src="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-light.svg?sanitize=true" width="500">
6
+ </picture>
7
+ </a>
8
+ <br>
9
+ <small>A web scraping and browser automation library</small>
10
+ </h1>
11
+
12
+ <p align=center>
13
+ <a href="https://trendshift.io/repositories/5179" target="_blank"><img src="https://trendshift.io/api/badge/repositories/5179" alt="apify%2Fcrawlee | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
14
+ </p>
15
+
16
+ <p align=center>
17
+ <a href="https://www.npmjs.com/package/@crawlee/core" rel="nofollow"><img src="https://img.shields.io/npm/v/@crawlee/core.svg" alt="NPM latest version" data-canonical-src="https://img.shields.io/npm/v/@crawlee/core/next.svg" style="max-width: 100%;"></a>
18
+ <a href="https://www.npmjs.com/package/@crawlee/core" rel="nofollow"><img src="https://img.shields.io/npm/dm/@crawlee/core.svg" alt="Downloads" data-canonical-src="https://img.shields.io/npm/dm/@crawlee/core.svg" style="max-width: 100%;"></a>
19
+ <a href="https://discord.gg/jyEM2PRvMU" rel="nofollow"><img src="https://img.shields.io/discord/801163717915574323?label=discord" alt="Chat on discord" data-canonical-src="https://img.shields.io/discord/801163717915574323?label=discord" style="max-width: 100%;"></a>
20
+ <a href="https://github.com/apify/crawlee/actions/workflows/test-ci.yml"><img src="https://github.com/apify/crawlee/actions/workflows/test-ci.yml/badge.svg?branch=master" alt="Build Status" style="max-width: 100%;"></a>
21
+ </p>
22
+
23
+ Crawlee covers your crawling and scraping end-to-end and **helps you build reliable scrapers. Fast.**
24
+
25
+ Your crawlers will appear human-like and fly under the radar of modern bot protections even with the default configuration. Crawlee gives you the tools to crawl the web for links, scrape data, and store it to disk or cloud while staying configurable to suit your project's needs.
26
+
27
+ Crawlee is available as the [`crawlee`](https://www.npmjs.com/package/crawlee) NPM package.
28
+
29
+ > 👉 **View full documentation, guides and examples on the [Crawlee project website](https://crawlee.dev)** 👈
30
+
31
+ > Do you prefer 🐍 Python instead of JavaScript? [👉 Checkout Crawlee for Python 👈](https://github.com/apify/crawlee-python).
32
+
33
+ ## Installation
34
+
35
+ We recommend visiting the [Introduction tutorial](https://crawlee.dev/js/docs/introduction) in Crawlee documentation for more information.
36
+
37
+ > Crawlee requires **Node.js 16 or higher**.
38
+
39
+ ### With Crawlee CLI
40
+
41
+ The fastest way to try Crawlee out is to use the **Crawlee CLI** and choose the **Getting started example**. The CLI will install all the necessary dependencies and add boilerplate code for you to play with.
42
+
43
+ ```bash
44
+ npx crawlee create my-crawler
45
+ ```
46
+
47
+ ```bash
48
+ cd my-crawler
49
+ npm start
50
+ ```
51
+
52
+ ### Manual installation
53
+ If you prefer adding Crawlee **into your own project**, try the example below. Because it uses `PlaywrightCrawler` we also need to install [Playwright](https://playwright.dev). It's not bundled with Crawlee to reduce install size.
54
+
55
+ ```bash
56
+ npm install crawlee playwright
57
+ ```
58
+
59
+ ```js
60
+ import { PlaywrightCrawler, Dataset } from 'crawlee';
61
+
62
+ // PlaywrightCrawler crawls the web using a headless
63
+ // browser controlled by the Playwright library.
64
+ const crawler = new PlaywrightCrawler({
65
+ // Use the requestHandler to process each of the crawled pages.
66
+ async requestHandler({ request, page, enqueueLinks, log }) {
67
+ const title = await page.title();
68
+ log.info(`Title of ${request.loadedUrl} is '${title}'`);
69
+
70
+ // Save results as JSON to ./storage/datasets/default
71
+ await Dataset.pushData({ title, url: request.loadedUrl });
72
+
73
+ // Extract links from the current page
74
+ // and add them to the crawling queue.
75
+ await enqueueLinks();
76
+ },
77
+ // Uncomment this option to see the browser window.
78
+ // headless: false,
79
+ });
80
+
81
+ // Add first URL to the queue and start the crawl.
82
+ await crawler.run(['https://crawlee.dev']);
83
+ ```
84
+
85
+ By default, Crawlee stores data to `./storage` in the current working directory. You can override this directory via Crawlee configuration. For details, see [Configuration guide](https://crawlee.dev/js/docs/guides/configuration), [Request storage](https://crawlee.dev/js/docs/guides/request-storage) and [Result storage](https://crawlee.dev/js/docs/guides/result-storage).
86
+
87
+ ### Installing pre-release versions
88
+
89
+ We provide automated beta builds for every merged code change in Crawlee. You can find them in the npm [list of releases](https://www.npmjs.com/package/crawlee?activeTab=versions). If you want to test new features or bug fixes before we release them, feel free to install a beta build like this:
90
+
91
+ ```bash
92
+ npm install crawlee@next
93
+ ```
94
+
95
+ If you also use the [Apify SDK](https://github.com/apify/apify-sdk-js), you need to specify dependency overrides in your `package.json` file so that you don't end up with multiple versions of Crawlee installed:
96
+
97
+ ```json
98
+ {
99
+ "overrides": {
100
+ "apify": {
101
+ "@crawlee/core": "$crawlee",
102
+ "@crawlee/types": "$crawlee",
103
+ "@crawlee/utils": "$crawlee"
104
+ }
105
+ }
106
+ }
107
+ ```
108
+
109
+ ## 🛠 Features
110
+
111
+ - Single interface for **HTTP and headless browser** crawling
112
+ - Persistent **queue** for URLs to crawl (breadth & depth first)
113
+ - Pluggable **storage** of both tabular data and files
114
+ - Automatic **scaling** with available system resources
115
+ - Integrated **proxy rotation** and session management
116
+ - Lifecycles customizable with **hooks**
117
+ - **CLI** to bootstrap your projects
118
+ - Configurable **routing**, **error handling** and **retries**
119
+ - **Dockerfiles** ready to deploy
120
+ - Written in **TypeScript** with generics
121
+
122
+ ### 👾 HTTP crawling
123
+
124
+ - Zero config **HTTP2 support**, even for proxies
125
+ - Automatic generation of **browser-like headers**
126
+ - Replication of browser **TLS fingerprints**
127
+ - Integrated fast **HTML parsers**. Cheerio and JSDOM
128
+ - Yes, you can scrape **JSON APIs** as well
129
+
130
+ ### 💻 Real browser crawling
131
+
132
+ - JavaScript **rendering** and **screenshots**
133
+ - **Headless** and **headful** support
134
+ - Zero-config generation of **human-like fingerprints**
135
+ - Automatic **browser management**
136
+ - Use **Playwright** and **Puppeteer** with the same interface
137
+ - **Chrome**, **Firefox**, **Webkit** and many others
138
+
139
+ ## Usage on the Apify platform
140
+
141
+ Crawlee is open-source and runs anywhere, but since it's developed by [Apify](https://apify.com), it's easy to set up on the Apify platform and run in the cloud. Visit the [Apify SDK website](https://sdk.apify.com) to learn more about deploying Crawlee to the Apify platform.
142
+
143
+ ## Support
144
+
145
+ If you find any bug or issue with Crawlee, please [submit an issue on GitHub](https://github.com/apify/crawlee/issues). For questions, you can ask on [Stack Overflow](https://stackoverflow.com/questions/tagged/apify), in GitHub Discussions or you can join our [Discord server](https://discord.com/invite/jyEM2PRvMU).
146
+
147
+ ## Contributing
148
+
149
+ Your code contributions are welcome, and you'll be praised to eternity! If you have any ideas for improvements, either submit an issue or create a pull request. For contribution guidelines and the code of conduct, see [CONTRIBUTING.md](https://github.com/apify/crawlee/blob/master/CONTRIBUTING.md).
150
+
151
+ ## License
152
+
153
+ This project is licensed under the Apache License 2.0 - see the [LICENSE.md](https://github.com/apify/crawlee/blob/master/LICENSE.md) file for details.
package/index.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * AI-powered web crawling with Stagehand integration for Crawlee.
3
+ *
4
+ * This package provides {@apilink StagehandCrawler}, which extends {@apilink BrowserCrawler}
5
+ * with natural language browser automation capabilities powered by Browserbase's Stagehand library.
6
+ *
7
+ * ## Key Features
8
+ *
9
+ * - **Natural Language Actions**: Use `page.act()` to perform actions with plain English instructions
10
+ * - **Structured Data Extraction**: Use `page.extract()` with Zod schemas for type-safe data extraction
11
+ * - **Action Discovery**: Use `page.observe()` to get AI-suggested actions
12
+ * - **Autonomous Agents**: Use `page.agent()` for complex multi-step workflows
13
+ * - **Anti-Blocking**: Automatic browser fingerprinting and Cloudflare bypass
14
+ * - **Browserbase Integration**: Optional cloud browser support
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { StagehandCrawler } from '@crawlee/stagehand';
19
+ * import { z } from 'zod';
20
+ *
21
+ * const crawler = new StagehandCrawler({
22
+ * stagehandOptions: {
23
+ * env: 'LOCAL',
24
+ * model: 'openai/gpt-4.1-mini',
25
+ * },
26
+ * async requestHandler({ page, request, log }) {
27
+ * log.info(`Processing ${request.url}`);
28
+ *
29
+ * // Use natural language to interact
30
+ * await page.act('Click the Products link');
31
+ *
32
+ * // Extract structured data
33
+ * const products = await page.extract(
34
+ * 'Get all products',
35
+ * z.object({
36
+ * items: z.array(z.object({
37
+ * name: z.string(),
38
+ * price: z.number(),
39
+ * })),
40
+ * })
41
+ * );
42
+ *
43
+ * await Dataset.pushData(products);
44
+ * },
45
+ * });
46
+ *
47
+ * await crawler.run(['https://example.com']);
48
+ * ```
49
+ *
50
+ * @module @crawlee/stagehand
51
+ */
52
+ export * from '@crawlee/browser';
53
+ export { StagehandCrawler, createStagehandRouter, } from './internals/stagehand-crawler';
54
+ export type { StagehandOptions, StagehandPage, StagehandCrawlingContext, StagehandHook, StagehandRequestHandler, StagehandGotoOptions, StagehandCrawlerOptions, } from './internals/stagehand-crawler';
55
+ export type { StagehandLaunchContext } from './internals/stagehand-launcher';
56
+ export * as stagehandUtils from './internals/utils/stagehand-utils';
57
+ export type { ActOptions, ActResult, Action, AgentConfig, AgentResult, ExtractOptions, ModelConfiguration, ObserveOptions, Stagehand, } from '@browserbasehq/stagehand';
58
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAGH,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EACH,gBAAgB,EAChB,qBAAqB,GACxB,MAAM,+BAA+B,CAAC;AAGvC,YAAY,EACR,gBAAgB,EAChB,aAAa,EACb,wBAAwB,EACxB,aAAa,EACb,uBAAuB,EACvB,oBAAoB,EACpB,uBAAuB,GAC1B,MAAM,+BAA+B,CAAC;AAEvC,YAAY,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAG7E,OAAO,KAAK,cAAc,MAAM,mCAAmC,CAAC;AAGpE,YAAY,EACR,UAAU,EACV,SAAS,EACT,MAAM,EACN,WAAW,EACX,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,SAAS,GACZ,MAAM,0BAA0B,CAAC"}
package/index.js ADDED
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ /**
3
+ * AI-powered web crawling with Stagehand integration for Crawlee.
4
+ *
5
+ * This package provides {@apilink StagehandCrawler}, which extends {@apilink BrowserCrawler}
6
+ * with natural language browser automation capabilities powered by Browserbase's Stagehand library.
7
+ *
8
+ * ## Key Features
9
+ *
10
+ * - **Natural Language Actions**: Use `page.act()` to perform actions with plain English instructions
11
+ * - **Structured Data Extraction**: Use `page.extract()` with Zod schemas for type-safe data extraction
12
+ * - **Action Discovery**: Use `page.observe()` to get AI-suggested actions
13
+ * - **Autonomous Agents**: Use `page.agent()` for complex multi-step workflows
14
+ * - **Anti-Blocking**: Automatic browser fingerprinting and Cloudflare bypass
15
+ * - **Browserbase Integration**: Optional cloud browser support
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { StagehandCrawler } from '@crawlee/stagehand';
20
+ * import { z } from 'zod';
21
+ *
22
+ * const crawler = new StagehandCrawler({
23
+ * stagehandOptions: {
24
+ * env: 'LOCAL',
25
+ * model: 'openai/gpt-4.1-mini',
26
+ * },
27
+ * async requestHandler({ page, request, log }) {
28
+ * log.info(`Processing ${request.url}`);
29
+ *
30
+ * // Use natural language to interact
31
+ * await page.act('Click the Products link');
32
+ *
33
+ * // Extract structured data
34
+ * const products = await page.extract(
35
+ * 'Get all products',
36
+ * z.object({
37
+ * items: z.array(z.object({
38
+ * name: z.string(),
39
+ * price: z.number(),
40
+ * })),
41
+ * })
42
+ * );
43
+ *
44
+ * await Dataset.pushData(products);
45
+ * },
46
+ * });
47
+ *
48
+ * await crawler.run(['https://example.com']);
49
+ * ```
50
+ *
51
+ * @module @crawlee/stagehand
52
+ */
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.stagehandUtils = exports.createStagehandRouter = exports.StagehandCrawler = void 0;
55
+ const tslib_1 = require("tslib");
56
+ // Re-export everything from @crawlee/browser for convenience
57
+ tslib_1.__exportStar(require("@crawlee/browser"), exports);
58
+ // Export main crawler class
59
+ var stagehand_crawler_1 = require("./internals/stagehand-crawler");
60
+ Object.defineProperty(exports, "StagehandCrawler", { enumerable: true, get: function () { return stagehand_crawler_1.StagehandCrawler; } });
61
+ Object.defineProperty(exports, "createStagehandRouter", { enumerable: true, get: function () { return stagehand_crawler_1.createStagehandRouter; } });
62
+ // Export utilities as namespace
63
+ exports.stagehandUtils = tslib_1.__importStar(require("./internals/utils/stagehand-utils"));
64
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;;;;AAEH,6DAA6D;AAC7D,2DAAiC;AAEjC,4BAA4B;AAC5B,mEAGuC;AAFnC,qHAAA,gBAAgB,OAAA;AAChB,0HAAA,qBAAqB,OAAA;AAgBzB,gCAAgC;AAChC,4FAAoE"}
package/index.mjs ADDED
@@ -0,0 +1,101 @@
1
+ import mod from "./index.js";
2
+
3
+ export default mod;
4
+ export const API_PROCESSED_REQUESTS_DELAY_MILLIS = mod.API_PROCESSED_REQUESTS_DELAY_MILLIS;
5
+ export const AutoscaledPool = mod.AutoscaledPool;
6
+ export const BASIC_CRAWLER_TIMEOUT_BUFFER_SECS = mod.BASIC_CRAWLER_TIMEOUT_BUFFER_SECS;
7
+ export const BLOCKED_STATUS_CODES = mod.BLOCKED_STATUS_CODES;
8
+ export const BasicCrawler = mod.BasicCrawler;
9
+ export const BrowserCrawler = mod.BrowserCrawler;
10
+ export const BrowserLauncher = mod.BrowserLauncher;
11
+ export const Configuration = mod.Configuration;
12
+ export const CookieParseError = mod.CookieParseError;
13
+ export const CrawlerExtension = mod.CrawlerExtension;
14
+ export const CriticalError = mod.CriticalError;
15
+ export const DATASET_ITERATORS_DEFAULT_LIMIT = mod.DATASET_ITERATORS_DEFAULT_LIMIT;
16
+ export const Dataset = mod.Dataset;
17
+ export const EVENT_SESSION_RETIRED = mod.EVENT_SESSION_RETIRED;
18
+ export const EnqueueStrategy = mod.EnqueueStrategy;
19
+ export const ErrorSnapshotter = mod.ErrorSnapshotter;
20
+ export const ErrorTracker = mod.ErrorTracker;
21
+ export const EventManager = mod.EventManager;
22
+ export const EventType = mod.EventType;
23
+ export const GotScrapingHttpClient = mod.GotScrapingHttpClient;
24
+ export const KeyValueStore = mod.KeyValueStore;
25
+ export const LocalEventManager = mod.LocalEventManager;
26
+ export const Log = mod.Log;
27
+ export const LogLevel = mod.LogLevel;
28
+ export const Logger = mod.Logger;
29
+ export const LoggerJson = mod.LoggerJson;
30
+ export const LoggerText = mod.LoggerText;
31
+ export const MAX_POOL_SIZE = mod.MAX_POOL_SIZE;
32
+ export const MAX_QUERIES_FOR_CONSISTENCY = mod.MAX_QUERIES_FOR_CONSISTENCY;
33
+ export const MissingRouteError = mod.MissingRouteError;
34
+ export const NonRetryableError = mod.NonRetryableError;
35
+ export const PERSIST_STATE_KEY = mod.PERSIST_STATE_KEY;
36
+ export const ProxyConfiguration = mod.ProxyConfiguration;
37
+ export const PseudoUrl = mod.PseudoUrl;
38
+ export const QUERY_HEAD_BUFFER = mod.QUERY_HEAD_BUFFER;
39
+ export const QUERY_HEAD_MIN_LENGTH = mod.QUERY_HEAD_MIN_LENGTH;
40
+ export const REQUESTS_PERSISTENCE_KEY = mod.REQUESTS_PERSISTENCE_KEY;
41
+ export const RecoverableState = mod.RecoverableState;
42
+ export const Request = mod.Request;
43
+ export const RequestHandlerResult = mod.RequestHandlerResult;
44
+ export const RequestList = mod.RequestList;
45
+ export const RequestListAdapter = mod.RequestListAdapter;
46
+ export const RequestManagerTandem = mod.RequestManagerTandem;
47
+ export const RequestProvider = mod.RequestProvider;
48
+ export const RequestQueue = mod.RequestQueue;
49
+ export const RequestQueueV1 = mod.RequestQueueV1;
50
+ export const RequestQueueV2 = mod.RequestQueueV2;
51
+ export const RequestState = mod.RequestState;
52
+ export const RetryRequestError = mod.RetryRequestError;
53
+ export const Router = mod.Router;
54
+ export const STATE_PERSISTENCE_KEY = mod.STATE_PERSISTENCE_KEY;
55
+ export const STORAGE_CONSISTENCY_DELAY_MILLIS = mod.STORAGE_CONSISTENCY_DELAY_MILLIS;
56
+ export const Session = mod.Session;
57
+ export const SessionError = mod.SessionError;
58
+ export const SessionPool = mod.SessionPool;
59
+ export const SitemapRequestList = mod.SitemapRequestList;
60
+ export const Snapshotter = mod.Snapshotter;
61
+ export const StagehandCrawler = mod.StagehandCrawler;
62
+ export const Statistics = mod.Statistics;
63
+ export const StorageManager = mod.StorageManager;
64
+ export const SystemStatus = mod.SystemStatus;
65
+ export const browserCrawlerEnqueueLinks = mod.browserCrawlerEnqueueLinks;
66
+ export const browserPoolCookieToToughCookie = mod.browserPoolCookieToToughCookie;
67
+ export const checkAndSerialize = mod.checkAndSerialize;
68
+ export const checkStorageAccess = mod.checkStorageAccess;
69
+ export const chunkBySize = mod.chunkBySize;
70
+ export const constructGlobObjectsFromGlobs = mod.constructGlobObjectsFromGlobs;
71
+ export const constructRegExpObjectsFromPseudoUrls = mod.constructRegExpObjectsFromPseudoUrls;
72
+ export const constructRegExpObjectsFromRegExps = mod.constructRegExpObjectsFromRegExps;
73
+ export const cookieStringToToughCookie = mod.cookieStringToToughCookie;
74
+ export const createBasicRouter = mod.createBasicRouter;
75
+ export const createDeserialize = mod.createDeserialize;
76
+ export const createRequestOptions = mod.createRequestOptions;
77
+ export const createRequests = mod.createRequests;
78
+ export const createStagehandRouter = mod.createStagehandRouter;
79
+ export const deserializeArray = mod.deserializeArray;
80
+ export const enqueueLinks = mod.enqueueLinks;
81
+ export const extractUrlsFromPage = mod.extractUrlsFromPage;
82
+ export const filterRequestsByPatterns = mod.filterRequestsByPatterns;
83
+ export const getCookiesFromResponse = mod.getCookiesFromResponse;
84
+ export const getDefaultCookieExpirationDate = mod.getDefaultCookieExpirationDate;
85
+ export const getRequestId = mod.getRequestId;
86
+ export const handleRequestTimeout = mod.handleRequestTimeout;
87
+ export const log = mod.log;
88
+ export const maybeStringify = mod.maybeStringify;
89
+ export const mergeCookies = mod.mergeCookies;
90
+ export const processHttpRequestOptions = mod.processHttpRequestOptions;
91
+ export const purgeDefaultStorages = mod.purgeDefaultStorages;
92
+ export const resolveBaseUrlForEnqueueLinksFiltering = mod.resolveBaseUrlForEnqueueLinksFiltering;
93
+ export const serializeArray = mod.serializeArray;
94
+ export const stagehandUtils = mod.stagehandUtils;
95
+ export const toughCookieToBrowserPoolCookie = mod.toughCookieToBrowserPoolCookie;
96
+ export const tryAbsoluteURL = mod.tryAbsoluteURL;
97
+ export const updateEnqueueLinksPatternCache = mod.updateEnqueueLinksPatternCache;
98
+ export const useState = mod.useState;
99
+ export const validateGlobPattern = mod.validateGlobPattern;
100
+ export const validators = mod.validators;
101
+ export const withCheckedStorageAccess = mod.withCheckedStorageAccess;
@@ -0,0 +1,55 @@
1
+ import type { Stagehand } from '@browserbasehq/stagehand';
2
+ import { BrowserController } from '@crawlee/browser-pool';
3
+ import type { Cookie } from '@crawlee/types';
4
+ import type { Browser as PlaywrightBrowser, BrowserType, LaunchOptions, Page } from 'playwright';
5
+ import type { StagehandPlugin } from './stagehand-plugin';
6
+ /**
7
+ * StagehandController manages the lifecycle of a Stagehand-controlled browser for Crawlee's BrowserPool.
8
+ *
9
+ * This controller bridges Crawlee's browser management system with Stagehand:
10
+ * - Created by StagehandPlugin when a new browser is needed
11
+ * - Provides page creation via Playwright (connected to Stagehand's browser via CDP)
12
+ * - Exposes the Stagehand instance so crawling context can access AI methods (act/extract/observe)
13
+ * - Handles browser cleanup by delegating to Stagehand's close method
14
+ *
15
+ * Proxy authentication is handled transparently via anonymizeProxy in the plugin layer.
16
+ *
17
+ * @ignore
18
+ */
19
+ export declare class StagehandController extends BrowserController<BrowserType, LaunchOptions, PlaywrightBrowser> {
20
+ private stagehand;
21
+ private readonly stagehandInstances;
22
+ constructor(browserPlugin: StagehandPlugin, stagehandInstances: WeakMap<PlaywrightBrowser, Stagehand>);
23
+ /**
24
+ * Gets the Stagehand instance associated with this controller's browser.
25
+ */
26
+ getStagehand(): Stagehand;
27
+ /**
28
+ * Creates a new page using the browser's default context.
29
+ * We use Playwright's browser API directly since we connected via CDP.
30
+ */
31
+ protected _newPage(_contextOptions?: unknown): Promise<Page>;
32
+ /**
33
+ * Normalizes proxy options for Playwright.
34
+ */
35
+ normalizeProxyOptions(proxyUrl: string | undefined, pageOptions: any): Record<string, unknown>;
36
+ /**
37
+ * Sets cookies in the browser context.
38
+ * Uses Playwright's browser context API directly.
39
+ */
40
+ protected _setCookies(page: Page, cookies: Cookie[]): Promise<void>;
41
+ /**
42
+ * Gets cookies from the browser context.
43
+ * Uses Playwright's browser context API directly.
44
+ */
45
+ protected _getCookies(page: Page): Promise<Cookie[]>;
46
+ /**
47
+ * Closes the browser and cleans up Stagehand resources.
48
+ */
49
+ protected _close(): Promise<void>;
50
+ /**
51
+ * Kills the browser process forcefully.
52
+ */
53
+ protected _kill(): Promise<void>;
54
+ }
55
+ //# sourceMappingURL=stagehand-controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stagehand-controller.d.ts","sourceRoot":"","sources":["../../src/internals/stagehand-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,IAAI,iBAAiB,EAAE,WAAW,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAIjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D;;;;;;;;;;;;GAYG;AACH,qBAAa,mBAAoB,SAAQ,iBAAiB,CAAC,WAAW,EAAE,aAAa,EAAE,iBAAiB,CAAC;IACrG,OAAO,CAAC,SAAS,CAA0B;IAC3C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAwC;gBAE/D,aAAa,EAAE,eAAe,EAAE,kBAAkB,EAAE,OAAO,CAAC,iBAAiB,EAAE,SAAS,CAAC;IAKrG;;OAEG;IACH,YAAY,IAAI,SAAS;IAUzB;;;OAGG;cACsB,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB3E;;OAEG;IACH,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,WAAW,EAAE,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAmB9F;;;OAGG;cACsB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IASlF;;;OAGG;cACsB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAUnE;;OAEG;cACsB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAUhD;;OAEG;cACsB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CASlD"}