Skip to content

Commit 522b139

Browse files
committed
add viewport to config
1 parent 4936b20 commit 522b139

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

browserbase/config.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ export type Config = {
3232
*/
3333
persist?: boolean;
3434
};
35+
/**
36+
*
37+
*/
38+
viewPort?: {
39+
/**
40+
* The width of the browser
41+
*/
42+
browserWidth?: number;
43+
/**
44+
* The height of the browser
45+
*/
46+
browserHeight?: number;
47+
};
3548
/**
3649
* Cookies to inject into the Browserbase context
3750
* Format: Array of cookie objects with name, value, domain, and optional path, expires, httpOnly, secure, sameSite

browserbase/src/config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export interface Config {
1818
contextId?: string;
1919
persist?: boolean;
2020
};
21+
viewPort?: {
22+
browserWidth?: number;
23+
browserHeight?: number;
24+
};
2125
cookies?: Cookie[];
2226
}
2327

@@ -31,6 +35,10 @@ export type CLIOptions = {
3135
port?: number;
3236
host?: string;
3337
cookies?: Cookie[];
38+
viewPort?: {
39+
browserWidth?: number;
40+
browserHeight?: number;
41+
};
3442
};
3543

3644
// Default Configuration Values
@@ -46,6 +54,10 @@ const defaultConfig: Config = {
4654
port: undefined,
4755
host: undefined,
4856
},
57+
viewPort: {
58+
browserWidth: 1024,
59+
browserHeight: 768,
60+
},
4961
cookies: undefined,
5062
};
5163

@@ -90,6 +102,10 @@ export async function configFromCLIOptions(cliOptions: CLIOptions): Promise<Conf
90102
contextId: cliOptions.contextId,
91103
persist: cliOptions.persist,
92104
},
105+
viewPort: {
106+
browserWidth: cliOptions.viewPort?.browserWidth,
107+
browserHeight: cliOptions.viewPort?.browserHeight,
108+
},
93109
cookies: cliOptions.cookies,
94110
};
95111
}

browserbase/src/program.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ program
2020
.option('--port <port>', 'Port to listen on for SSE transport.')
2121
.option('--host <host>', 'Host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces.')
2222
.option('--cookies [json]', 'JSON array of cookies to inject into the browser. Format: [{"name":"cookie1","value":"val1","domain":"example.com"}, ...]')
23+
.option('--viewPort [json]', 'ViewPort to use for the browser. Format: {"browserWidth":1024,"browserHeight":768}')
2324
.action(async options => {
2425
const config = await resolveConfig(options);
2526
const serverList = new ServerList(async() => createServer(config));

browserbase/src/sessionManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ export async function createNewBrowserSession(
9393
proxies: config.proxies,
9494
browserSettings: {
9595
viewport: { // better for snapshots
96-
width: 1024,
97-
height: 768,
96+
width: config.viewPort?.browserWidth,
97+
height: config.viewPort?.browserHeight,
9898
},
9999
},
100100
};

0 commit comments

Comments
 (0)