{"record":{"id":"2164586497491412","repo":"microsoft/playwright","slug":"device-emulation-is-not-supported-with-cdpendpoint","errorCode":null,"errorMessage":"Device emulation is not supported with cdpEndpoint.","messagePattern":"Device emulation is not supported with cdpEndpoint\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/tools/mcp/config.ts","lineNumber":316,"sourceCode":"    headless: cliOptions.headless,\n  };\n\n  // --sandbox was passed, enable the sandbox\n  // --no-sandbox was passed, disable the sandbox\n  if (cliOptions.sandbox !== undefined)\n    launchOptions.chromiumSandbox = cliOptions.sandbox;\n\n  let device = cliOptions.device;\n  if (cliOptions.mobile) {\n    if (device)\n      throw new Error('Cannot use --mobile together with --device, pick one.');\n    if (browserName === 'firefox')\n      throw new Error('--mobile is not supported with the Firefox browser.');\n    device = browserName === 'webkit' ? 'iPhone 17' : 'Pixel 10';\n  }\n\n  if (device && cliOptions.cdpEndpoint)\n    throw new Error('Device emulation is not supported with cdpEndpoint.');\n\n  // Context options\n  const contextOptions: playwrightTypes.BrowserContextOptions = device ? playwright.devices[device] : {};\n\n  if (cliOptions.proxyServer) {\n    const proxy: playwrightTypes.LaunchOptions['proxy'] = { server: cliOptions.proxyServer };\n    if (cliOptions.proxyBypass)\n      proxy.bypass = cliOptions.proxyBypass;\n    // Set on both to ensure CLI takes precedence over any proxy set in the config file\n    // (launchOptions.proxy applies at browser launch, contextOptions.proxy at context creation).\n    launchOptions.proxy = proxy;\n    contextOptions.proxy = proxy;\n  }\n\n  if (cliOptions.storageState)\n    contextOptions.storageState = cliOptions.storageState;\n\n  if (cliOptions.userAgent)","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/tools/mcp/config.ts#L298-L334","documentation":"Thrown by configFromCLIOptions() when a device preset is active (either --device or --mobile) and --cdpEndpoint is also set. Device emulation is applied as context options on a freshly created context, but a CDP endpoint connects to an already-running browser whose context Playwright does not own, so the emulation options cannot be honored reliably.","triggerScenarios":"Combining `--device \"Pixel 10\" --cdp-endpoint ws://host:9222` or `--mobile --cdp-endpoint ...` on the MCP CLI.","commonSituations":"Wanting to drive an existing Chrome instance (e.g. for debugging or a pre-launched browser) while also wanting mobile emulation; leftover --device from a previous run combined with a new --cdp-endpoint.","solutions":["Drop --device/--mobile when connecting via --cdp-endpoint, and configure emulation inside the target browser instead.","If you need device emulation, remove --cdp-endpoint so Playwright launches and owns the browser context.","If both are required, launch a browser with the device profile locally and expose its CDP endpoint yourself, then connect without --device."],"exampleFix":"// before\nplaywright mcp --device \"Pixel 10\" --cdp-endpoint ws://localhost:9222\n// after (own the browser)\nplaywright mcp --device \"Pixel 10\"\n// after (use existing browser, no emulation)\nplaywright mcp --cdp-endpoint ws://localhost:9222","handlingStrategy":"validation","validationCode":"if ((cliOptions.device || cliOptions.mobile) && cliOptions.cdpEndpoint) {\n  throw new Error('Device emulation cannot be combined with --cdp-endpoint.');\n}","typeGuard":"function deviceEmulationActive(opts: { device?: string; mobile?: boolean }): boolean {\n  return Boolean(opts.device) || Boolean(opts.mobile);\n}","tryCatchPattern":null,"preventionTips":["Decide upfront whether you own the browser (launch + emulate) or connect to one (cdp).","Validate CLI options in a wrapper to reject incompatible combinations before launch.","Avoid templating device and cdp-endpoint from independent config sources."],"tags":["mcp","config","cli","device-emulation","cdp","validation"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}