diff --git a/docs/reference/initialization_config.mdx b/docs/reference/initialization_config.mdx index 8fa159399..94048ad9c 100644 --- a/docs/reference/initialization_config.mdx +++ b/docs/reference/initialization_config.mdx @@ -481,7 +481,9 @@ This constructor is used to create an instance of Stagehand. - + + The size of the viewport. If set to `null`, the viewport will be set to the size of the operating system window. Defaults to `{ width: 1024, height: 768 }`. + Width of the viewport. diff --git a/lib/index.ts b/lib/index.ts index 8e534ed87..f0c47d1d7 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -280,13 +280,19 @@ async function getBrowser( const context = await chromium.launchPersistentContext(userDataDir, { acceptDownloads: localBrowserLaunchOptions?.acceptDownloads ?? true, headless: localBrowserLaunchOptions?.headless ?? headless, - viewport: { - width: localBrowserLaunchOptions?.viewport?.width ?? 1024, - height: localBrowserLaunchOptions?.viewport?.height ?? 768, - }, + viewport: + localBrowserLaunchOptions?.viewport === null + ? null + : { + width: localBrowserLaunchOptions?.viewport?.width ?? 1024, + height: localBrowserLaunchOptions?.viewport?.height ?? 768, + }, locale: localBrowserLaunchOptions?.locale ?? "en-US", timezoneId: localBrowserLaunchOptions?.timezoneId ?? "America/New_York", - deviceScaleFactor: localBrowserLaunchOptions?.deviceScaleFactor ?? 1, + deviceScaleFactor: + localBrowserLaunchOptions?.viewport === null + ? undefined + : (localBrowserLaunchOptions?.deviceScaleFactor ?? 1), args: localBrowserLaunchOptions?.args ?? [ "--disable-blink-features=AutomationControlled", ], diff --git a/types/stagehand.ts b/types/stagehand.ts index d6ed42d85..88b2d5e8a 100644 --- a/types/stagehand.ts +++ b/types/stagehand.ts @@ -198,7 +198,7 @@ export interface LocalBrowserLaunchOptions { urlFilter?: string | RegExp; }; recordVideo?: { dir: string; size?: { width: number; height: number } }; - viewport?: { width: number; height: number }; + viewport?: { width: number; height: number } | null; deviceScaleFactor?: number; timezoneId?: string; bypassCSP?: boolean;