Skip to content

Commit fc0c9e5

Browse files
remove extra lint
1 parent 8eccd56 commit fc0c9e5

File tree

2 files changed

+41
-34
lines changed

2 files changed

+41
-34
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,15 @@
233233
We're thrilled to announce the release of Stagehand 2.0, bringing significant improvements to make browser automation more powerful, faster, and easier to use than ever before.
234234

235235
### 🚀 New Features
236+
236237
- **Introducing `stagehand.agent`**: A powerful new way to integrate SOTA Computer use models or Browserbase's [Open Operator](https://operator.browserbase.com) into Stagehand with one line of code! Perfect for multi-step workflows and complex interactions. [Learn more](https://docs.stagehand.dev/concepts/agent)
237238
- **Lightning-fast `act` and `extract`**: Major performance improvements to make your automations run significantly faster.
238239
- **Enhanced Logging**: Better visibility into what's happening during automation with improved logging and debugging capabilities.
239240
- **Comprehensive Documentation**: A completely revamped documentation site with better examples, guides, and best practices.
240241
- **Improved Error Handling**: More descriptive errors and better error recovery to help you debug issues faster.
241242

242243
### 🛠️ Developer Experience
244+
243245
- **Better TypeScript Support**: Enhanced type definitions and better IDE integration
244246
- **Better Error Messages**: Clearer, more actionable error messages to help you debug faster
245247
- **Improved Caching**: More reliable action caching for better performance
@@ -500,6 +502,7 @@
500502
- [#316](https://github.com/browserbase/stagehand/pull/316) [`902e633`](https://github.com/browserbase/stagehand/commit/902e633e126a58b80b757ea0ecada01a7675a473) Thanks [@kamath](https://github.com/kamath)! - rename browserbaseResumeSessionID -> browserbaseSessionID
501503

502504
- [#296](https://github.com/browserbase/stagehand/pull/296) [`f11da27`](https://github.com/browserbase/stagehand/commit/f11da27a20409c240ceeea2003d520f676def61a) Thanks [@kamath](https://github.com/kamath)! - - Deprecate fields in `init` in favor of constructor options
505+
503506
- Deprecate `initFromPage` in favor of `browserbaseResumeSessionID` in constructor
504507
- Rename `browserBaseSessionCreateParams` -> `browserbaseSessionCreateParams`
505508

lib/StagehandPage.ts

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import type { CDPSession, Page as PlaywrightPage, Frame } from "playwright";
22
import { selectors } from "playwright";
33
import { z } from "zod/v3";
4-
import { Page, defaultExtractSchema } from "../types/page";
4+
import {
5+
Page,
6+
defaultExtractSchema,
7+
StagehandScreenshotOptions,
8+
} from "../types/page";
59
import {
610
ExtractOptions,
711
ExtractResult,
@@ -415,37 +419,41 @@ ${scriptContent} \
415419
}
416420

417421
// Handle screenshots with CDP
418-
if (prop === "screenshot" && this.stagehand.env === "BROWSERBASE") {
419-
return async (
420-
options: {
421-
type?: "png" | "jpeg";
422-
quality?: number;
423-
fullPage?: boolean;
424-
clip?: { x: number; y: number; width: number; height: number };
425-
omitBackground?: boolean;
426-
} = {},
427-
) => {
428-
const cdpOptions: Record<string, unknown> = {
429-
format: options.type === "jpeg" ? "jpeg" : "png",
430-
quality: options.quality,
431-
clip: options.clip,
432-
omitBackground: options.omitBackground,
433-
fromSurface: true,
434-
};
435-
436-
if (options.fullPage) {
437-
cdpOptions.captureBeyondViewport = true;
438-
}
422+
if (prop === "screenshot") {
423+
return async (options: StagehandScreenshotOptions = {}) => {
424+
const rawScreenshot: typeof target.screenshot =
425+
Object.getPrototypeOf(target).screenshot.bind(target);
426+
427+
const {
428+
useCDP = this.stagehand.env === "BROWSERBASE",
429+
...playwrightOptions
430+
} = options;
431+
432+
if (useCDP && this.stagehand.env === "BROWSERBASE") {
433+
const cdpOptions: Record<string, unknown> = {
434+
format: options.type === "jpeg" ? "jpeg" : "png",
435+
quality: options.quality,
436+
clip: options.clip,
437+
omitBackground: options.omitBackground,
438+
fromSurface: true,
439+
};
440+
441+
if (options.fullPage) {
442+
cdpOptions.captureBeyondViewport = true;
443+
}
439444

440-
const data = await this.sendCDP<{ data: string }>(
441-
"Page.captureScreenshot",
442-
cdpOptions,
443-
);
445+
const data = await this.sendCDP<{ data: string }>(
446+
"Page.captureScreenshot",
447+
cdpOptions,
448+
);
444449

445-
// Convert base64 to buffer
446-
const buffer = Buffer.from(data.data, "base64");
450+
// Convert base64 to buffer
451+
const buffer = Buffer.from(data.data, "base64");
447452

448-
return buffer;
453+
return buffer;
454+
} else {
455+
return await rawScreenshot(playwrightOptions);
456+
}
449457
};
450458
}
451459

@@ -739,7 +747,6 @@ ${scriptContent} \
739747
const result = await this.api.act({
740748
...observeResult,
741749
frameId: this.rootFrameId,
742-
modelClientOptions: this.stagehand["modelClientOptions"],
743750
});
744751
this.stagehand.addToHistory("act", observeResult, result);
745752
return result;
@@ -837,10 +844,7 @@ ${scriptContent} \
837844
if (!instructionOrOptions) {
838845
let result: ExtractResult<T>;
839846
if (this.api) {
840-
result = await this.api.extract<T>({
841-
frameId: this.rootFrameId,
842-
modelClientOptions: this.stagehand["modelClientOptions"],
843-
});
847+
result = await this.api.extract<T>({ frameId: this.rootFrameId });
844848
} else {
845849
result = await this.extractHandler.extract();
846850
}

0 commit comments

Comments
 (0)