Repository: microsoft/playwright
File: packages/playwright/src/mcp/browser/config.ts (TypeScript)

Code before:
  result = mergeConfig(result, envOverrides.config);
  result = mergeConfig(result, cliOverrides.config);

  if (cliOptions.daemonSession)
    result.skillMode = true;

  if (!result.browser.userDataDir && daemonOverrides.sessionConfig?.userDataDirPrefix) {
    // No custom value provided, use the daemon data dir.
    const browserToken = result.browser.launchOptions?.channel ?? result.browser?.browserName;
    const userDataDir = `${daemonOverrides.sessionConfig.userDataDirPrefix}-${browserToken}`;
    result.browser.userDataDir = userDataDir;
  }

  if (result.browser.browserName === 'chromium' && result.browser.launchOptions.chromiumSandbox === undefined) {
    if (process.platform === 'linux')
      result.browser.launchOptions.chromiumSandbox = result.browser.launchOptions.channel !== 'chromium';
    else
      result.browser.launchOptions.chromiumSandbox = true;
  }

  result.configFile = configFile;
  result.sessionConfig = daemonOverrides.sessionConfig;

  // Daemon has different defaults.
  if (result.sessionConfig && result.browser.launchOptions.headless !== false && !result.browser.contextOptions.viewport)
    result.browser.contextOptions.viewport = { width: 1280, height: 720 };

  await validateConfig(result);

  return result;
}

async function validateConfig(config: FullConfig): Promise<void> {
  if (config.browser.initScript) {
    for (const script of config.browser.initScript) {
      if (!await fileExistsAsync(script))
        throw new Error(`Init script file does not exist: ${script}`);
    }
  }
  if (config.browser.initPage) {
    for (const page of config.browser.initPage) {
      if (!await fileExistsAsync(page))
        throw new Error(`Init page file does not exist: ${page}`);
    }
  }
  if (config.sharedBrowserContext && config.saveVideo)
    throw new Error('saveVideo is not supported when sharedBrowserContext is true');
}

export function configFromCLIOptions(cliOptions: CLIOptions): { config: Config, configFile?: string } {
  let browserName: 'chromium' | 'firefox' | 'webkit' | undefined;

Review comment (suggestion):
```suggestion
    result.browser.contextOptions.viewport ??= { width: 1280, height: 720 };
```

Code after:
  result = mergeConfig(result, envOverrides);
  result = mergeConfig(result, cliOverrides);

  if (daemonOverrides.sessionConfig) {
    result.skillMode = true;

    if (!result.extension && !result.browser.userDataDir && daemonOverrides.sessionConfig.userDataDirPrefix) {
      // No custom value provided, use the daemon data dir.
      const browserToken = result.browser.launchOptions?.channel ?? result.browser?.browserName;
      const userDataDir = `${daemonOverrides.sessionConfig.userDataDirPrefix}-${browserToken}`;
      result.browser.userDataDir = userDataDir;
    }
  }

  if (result.browser.browserName === 'chromium' && result.browser.launchOptions.chromiumSandbox === undefined) {
    if (process.platform === 'linux')
      result.browser.launchOptions.chromiumSandbox = result.browser.launchOptions.channel !== 'chromium';
    else
      result.browser.launchOptions.chromiumSandbox = true;
  }

  result.configFile = configFile;
  result.sessionConfig = daemonOverrides.sessionConfig;

  // Daemon has different defaults.
  if (result.sessionConfig && result.browser.launchOptions.headless !== false)
    result.browser.contextOptions.viewport ??= { width: 1280, height: 720 };

  await validateConfig(result);

  return result;
}

async function validateConfig(config: FullConfig): Promise<void> {
  if (config.browser.initScript) {
    for (const script of config.browser.initScript) {
      if (!await fileExistsAsync(script))
        throw new Error(`Init script file does not exist: ${script}`);
    }
  }
  if (config.browser.initPage) {
    for (const page of config.browser.initPage) {
      if (!await fileExistsAsync(page))
        throw new Error(`Init page file does not exist: ${page}`);
    }
  }
  if (config.sharedBrowserContext && config.saveVideo)
    throw new Error('saveVideo is not supported when sharedBrowserContext is true');
}

export function configFromCLIOptions(cliOptions: CLIOptions): Config & { configFile?: string } {