Skip to content

Commit 21c6578

Browse files
committed
conditionals for context and viewport + viewport config flag fix
1 parent 522b139 commit 21c6578

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

browserbase/src/config.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ export type CLIOptions = {
3535
port?: number;
3636
host?: string;
3737
cookies?: Cookie[];
38-
viewPort?: {
39-
browserWidth?: number;
40-
browserHeight?: number;
41-
};
38+
browserWidth?: number;
39+
browserHeight?: number;
4240
};
4341

4442
// Default Configuration Values
@@ -103,8 +101,8 @@ export async function configFromCLIOptions(cliOptions: CLIOptions): Promise<Conf
103101
persist: cliOptions.persist,
104102
},
105103
viewPort: {
106-
browserWidth: cliOptions.viewPort?.browserWidth,
107-
browserHeight: cliOptions.viewPort?.browserHeight,
104+
browserWidth: cliOptions.browserWidth,
105+
browserHeight: cliOptions.browserHeight,
108106
},
109107
cookies: cliOptions.cookies,
110108
};

browserbase/src/program.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ 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}')
23+
.option('--browserWidth <width>', 'Browser width to use for the browser.')
24+
.option('--browserHeight <height>', 'Browser height to use for the browser.')
2425
.action(async options => {
2526
const config = await resolveConfig(options);
2627
const serverList = new ServerList(async() => createServer(config));

browserbase/src/sessionManager.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export async function addCookiesToContext(context: any, cookies: Cookie[]): Prom
7373
// Function to create a new Browserbase session and connect Playwright
7474
export async function createNewBrowserSession(
7575
newSessionId: string,
76-
config: Config, // Accept config object
76+
config: Config,
7777
): Promise<BrowserSession> {
7878
if (!config.browserbaseApiKey) {
7979
throw new Error("Browserbase API Key is missing in the configuration.");
@@ -92,24 +92,17 @@ export async function createNewBrowserSession(
9292
projectId: config.browserbaseProjectId!,
9393
proxies: config.proxies,
9494
browserSettings: {
95-
viewport: { // better for snapshots
95+
...(config.viewPort ? { viewport: {
9696
width: config.viewPort?.browserWidth,
9797
height: config.viewPort?.browserHeight,
98-
},
98+
}} : {}),
99+
...(config.context?.contextId ? { context: {
100+
id: config.context?.contextId,
101+
persist: config.context?.persist ?? true, // Default to true if not specified
102+
}} : {})
99103
},
100104
};
101105

102-
console.error("config.context", config.context);
103-
// Add context settings if provided
104-
if (config.context?.contextId) {
105-
sessionOptions.browserSettings = {
106-
context: {
107-
id: config.context.contextId,
108-
persist: config.context.persist || true, // Default to true if not specified
109-
},
110-
};
111-
}
112-
113106
try {
114107
process.stderr.write(
115108
`[SessionManager] Creating session ${newSessionId}...\n`

0 commit comments

Comments
 (0)