File tree 3 files changed +41
-1
lines changed
3 files changed +41
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @browserbasehq/stagehand " : patch
3
+ ---
4
+
5
+ Added CDP support for screenshots, find more about the benefits here: https://docs.browserbase.com/features/screenshots#why-use-cdp-for-screenshots%3F
Original file line number Diff line number Diff line change @@ -251,6 +251,41 @@ export class StagehandPage {
251
251
} ;
252
252
}
253
253
254
+ // Handle screenshots with CDP
255
+ if ( prop === "screenshot" ) {
256
+ return async (
257
+ options : {
258
+ type ?: "png" | "jpeg" ;
259
+ quality ?: number ;
260
+ fullPage ?: boolean ;
261
+ clip ?: { x : number ; y : number ; width : number ; height : number } ;
262
+ omitBackground ?: boolean ;
263
+ } = { } ,
264
+ ) => {
265
+ const cdpOptions : Record < string , unknown > = {
266
+ format : options . type === "jpeg" ? "jpeg" : "png" ,
267
+ quality : options . quality ,
268
+ clip : options . clip ,
269
+ omitBackground : options . omitBackground ,
270
+ fromSurface : true ,
271
+ } ;
272
+
273
+ if ( options . fullPage ) {
274
+ cdpOptions . captureBeyondViewport = true ;
275
+ }
276
+
277
+ const data = await this . sendCDP < { data : string } > (
278
+ "Page.captureScreenshot" ,
279
+ cdpOptions ,
280
+ ) ;
281
+
282
+ // Convert base64 to buffer
283
+ const buffer = Buffer . from ( data . data , "base64" ) ;
284
+
285
+ return buffer ;
286
+ } ;
287
+ }
288
+
254
289
// Handle goto specially
255
290
if ( prop === "goto" ) {
256
291
return async ( url : string , options : GotoOptions ) => {
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ const StagehandConfig: ConstructorParams = {
10
10
: "LOCAL" ,
11
11
apiKey : process . env . BROWSERBASE_API_KEY /* API key for authentication */ ,
12
12
projectId : process . env . BROWSERBASE_PROJECT_ID /* Project identifier */ ,
13
- debugDom : true /* Enable DOM debugging features */ ,
13
+ debugDom : false /* Enable DOM debugging features */ ,
14
14
headless : false /* Run browser in headless mode */ ,
15
15
logger : ( message : LogLine ) =>
16
16
console . log ( logLineToString ( message ) ) /* Custom logging function */ ,
You can’t perform that action at this time.
0 commit comments