{"record":{"id":"426cb37bf04c7369","repo":"microsoft/playwright","slug":"devicescalefactor-option-is-not-supported-with-n","errorCode":null,"errorMessage":"\"deviceScaleFactor\" option is not supported with null \"viewport\"","messagePattern":"\"deviceScaleFactor\" option is not supported with null \"viewport\"","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/server/browserContext.ts","lineNumber":760,"sourceCode":"    await Promise.all(this.pages().map(page => page.safeNonStallingEvaluateInAllFrames(expression, world, options)));\n  }\n\n  addRouteInFlight(route: network.Route) {\n    this._routesInFlight.add(route);\n  }\n\n  removeRouteInFlight(route: network.Route) {\n    this._routesInFlight.delete(route);\n  }\n\n  async notifyRoutesInFlightAboutRemovedHandler(handler: network.RouteHandler): Promise<void> {\n    await Promise.all([...this._routesInFlight].map(route => route.removeHandler(handler)));\n  }\n}\n\nexport function validateBrowserContextOptions(options: types.BrowserContextOptions, browserOptions: BrowserOptions) {\n  if (options.noDefaultViewport && options.deviceScaleFactor !== undefined)\n    throw new Error(`\"deviceScaleFactor\" option is not supported with null \"viewport\"`);\n  if (options.noDefaultViewport && !!options.isMobile)\n    throw new Error(`\"isMobile\" option is not supported with null \"viewport\"`);\n  if (options.acceptDownloads === undefined && browserOptions.name !== 'electron')\n    options.acceptDownloads = 'accept';\n  // Electron requires explicit acceptDownloads: true since we wait for\n  // https://github.com/electron/electron/pull/41718 to be widely shipped.\n  // In 6-12 months, we can remove this check.\n  else if (options.acceptDownloads === undefined && browserOptions.name === 'electron')\n    options.acceptDownloads = 'internal-browser-default';\n  if (!options.viewport && !options.noDefaultViewport)\n    options.viewport = { width: 1280, height: 720 };\n  if (options.proxy)\n    options.proxy = normalizeProxySettings(options.proxy);\n  verifyGeolocation(options.geolocation);\n}\n\nexport function findMatchingHttpCredentials(credentials: HttpCredentials[] | undefined, url: string): HttpCredentials | undefined {\n  const origin = new URL(url).origin.toLowerCase();","sourceCodeStart":742,"sourceCodeEnd":778,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/server/browserContext.ts#L742-L778","documentation":"`validateBrowserContextOptions` rejects combining `noDefaultViewport: true` (null viewport) with `deviceScaleFactor`, because without a viewport Playwright cannot apply a device scale factor — the browser window itself is the viewport.","triggerScenarios":"`browser.newContext({ noDefaultViewport: true, deviceScaleFactor: 2 })` or `{ viewport: null, deviceScaleFactor: 2 }`.","commonSituations":"Switching to headless/windowed mode with `viewport: null` while keeping deviceScaleFactor from a previous config; desktop-automation setups reusing mobile configs.","solutions":["Remove `deviceScaleFactor` when using `noDefaultViewport` / `viewport: null`","Or set an explicit viewport so deviceScaleFactor applies"],"exampleFix":"// before\nawait browser.newContext({ viewport: null, deviceScaleFactor: 2 });\n\n// after\nawait browser.newContext({ viewport: null });","handlingStrategy":"validation","validationCode":"function validateContextOpts(o: { viewport?: null; noDefaultViewport?: boolean; deviceScaleFactor?: number; isMobile?: boolean }) {\n  const nullVp = o.viewport === null || !!o.noDefaultViewport;\n  if (nullVp && o.deviceScaleFactor !== undefined)\n    throw new Error('deviceScaleFactor requires a viewport (remove noDefaultViewport).');\n  if (nullVp && !!o.isMobile)\n    throw new Error('isMobile requires a viewport (remove noDefaultViewport).');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't combine viewport:null/noDefaultViewport with deviceScaleFactor or isMobile","Review config when switching to windowed mode","Validate context options in a shared helper before launch"],"tags":["browser-context","viewport","config","validation"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}