@@ -12,11 +12,20 @@ const consoleLogs: string[] = [];
12
12
const screenshots = new Map < string , string > ( ) ;
13
13
const defaultDownloadsPath = path . join ( os . homedir ( ) , 'Downloads' ) ;
14
14
15
- async function ensureBrowser ( ) {
15
+ // Viewport type definition
16
+ type ViewportSize = {
17
+ width ?: number ;
18
+ height ?: number ;
19
+ } ;
20
+
21
+ async function ensureBrowser ( viewport ?: ViewportSize ) {
16
22
if ( ! browser ) {
17
23
browser = await chromium . launch ( { headless : false } ) ;
18
24
const context = await browser . newContext ( {
19
- viewport : { width : 1920 , height : 1080 } ,
25
+ viewport : {
26
+ width : viewport ?. width ?? 1920 ,
27
+ height : viewport ?. height ?? 1080 ,
28
+ } ,
20
29
deviceScaleFactor : 1 ,
21
30
} ) ;
22
31
@@ -51,7 +60,10 @@ export async function handleToolCall(
51
60
52
61
// Only launch browser if the tool requires browser interaction
53
62
if ( requiresBrowser ) {
54
- page = await ensureBrowser ( ) ;
63
+ page = await ensureBrowser ( {
64
+ width : args . width ,
65
+ height : args . height
66
+ } ) ;
55
67
}
56
68
57
69
// Set up API context for API-related operations
@@ -70,7 +82,8 @@ export async function handleToolCall(
70
82
toolResult : {
71
83
content : [ {
72
84
type : "text" ,
73
- text : `Navigated to ${ args . url } with ${ args . waitUntil || "load" } wait` ,
85
+ text : `Navigated to ${ args . url } with ${ args . waitUntil || "load" } wait` +
86
+ ( args . width && args . height ? ` (viewport: ${ args . width } x${ args . height } )` : "" ) ,
74
87
} ] ,
75
88
isError : false ,
76
89
} ,
0 commit comments