{"record":{"id":"574217a7300be2ba","repo":"microsoft/playwright","slug":"invalid-viewport-size-format-use-width-height","errorCode":null,"errorMessage":"Invalid viewport size format: use \"width,height\", for example --viewport-size=\"800,600\"","messagePattern":"Invalid viewport size format: use \"width,height\", for example --viewport-size=\"800,600\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/cli/browserActions.ts","lineNumber":109,"sourceCode":"  // Proxy\n\n  if (options.proxyServer) {\n    launchOptions.proxy = {\n      server: options.proxyServer\n    };\n    if (options.proxyBypass)\n      launchOptions.proxy.bypass = options.proxyBypass;\n  }\n\n  // Viewport size\n  if (options.viewportSize) {\n    try {\n      const [width, height] = options.viewportSize.split(',').map(n => +n);\n      if (isNaN(width) || isNaN(height))\n        throw new Error('bad values');\n      contextOptions.viewport = { width, height };\n    } catch (e) {\n      throw new Error('Invalid viewport size format: use \"width,height\", for example --viewport-size=\"800,600\"');\n    }\n  }\n\n  // Geolocation\n\n  if (options.geolocation) {\n    try {\n      const [latitude, longitude] = options.geolocation.split(',').map(n => parseFloat(n.trim()));\n      contextOptions.geolocation = {\n        latitude,\n        longitude\n      };\n    } catch (e) {\n      throw new Error('Invalid geolocation format, should be \"lat,long\". For example --geolocation=\"37.819722,-122.478611\"');\n    }\n    contextOptions.permissions = ['geolocation'];\n  }\n","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/cli/browserActions.ts#L91-L127","documentation":"Thrown by the `--viewport-size` CLI option handler in browserActions when splitting the value into width,height fails to yield two finite numbers. The handler does `value.split(',').map(n => +n)` and throws a sentinel 'bad values' error inside a try, rethrown as the user-facing format message.","triggerScenarios":"Running `playwright open --viewport-size=...` (or screenshot/pdf commands) with a value missing the comma, non-numeric components, or empty string: `--viewport-size=800`, `--viewport-size=800,x`, `--viewport-size=abc,def`.","commonSituations":"Typo omitting the comma; locale using a different separator; copy-pasting a `WxH` form instead of `W,H`; empty env var feeding the flag.","solutions":["Use the `width,height` form exactly, e.g. `--viewport-size=\"800,600\"`.","If sourcing from an env var, validate/transform it before passing to the CLI.","Quote the value to avoid shell splitting."],"exampleFix":"# before\nnpx playwright open --viewport-size=800x600 https://example.com\n\n# after\nnpx playwright open --viewport-size=\"800,600\" https://example.com","handlingStrategy":"validation","validationCode":"function parseViewportSize(raw: string): { width: number; height: number } {\n  const parts = (raw ?? '').split(',');\n  if (parts.length !== 2) throw new Error('Use \"width,height\" e.g. \"800,600\"');\n  const [w, h] = parts.map(Number);\n  if (!Number.isFinite(w) || !Number.isFinite(h) || w <= 0 || h <= 0)\n    throw new Error('width and height must be positive numbers');\n  return { width: w, height: h };\n}","typeGuard":"function isViewportString(v: string): boolean {\n  const m = v.match(/^(\\d+),(\\d+)$/);\n  return !!m && +m[1] > 0 && +m[2] > 0;\n}","tryCatchPattern":"try {\n  return parseViewportSize(raw);\n} catch (e) {\n  if (/Invalid viewport size format/.test(e.message)) {\n    throw new Error(`Expected \"W,H\" (e.g. \"800,600\"), got ${JSON.stringify(raw)}`);\n  }\n  throw e;\n}","preventionTips":["Validate the env-supplied viewport before forwarding it to the CLI.","Quote `--viewport-size=\"800,600\"` so the shell does not split it.","Normalize locale-specific separators to a comma."],"tags":["cli","viewport","validation","user-input"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}