title: Chrome mobile emulation. Window size is different via Selenium and Devtools
body: <p>Need to test web site responsibility.
  Code example taken from <a href="http://chromedriver.chromium.org/mobile-emulation" rel="nofollow noreferrer">here</a> (in the bottom of page)
  Faced, that selenium opens chrome window in different size/resolution, than i expect. Looks like that pixelRatio is not accepted or accepted incorrectly.
  Also, faced, that in devtools, devices size from default device list is already divided on pixelRatio. e.g. Iphone 6 has 750 x 1334 and pixelRatio 2.0, but in devtools it is 375 x 667 which perfectly fits <strong><em>original resolution</em></strong> divided on <strong><em>pixelRatio</em></strong>. But if I manually add custom device 750 x 1334 with pixelRatio 2.0, it still shows me 750 x 1334
  In <a href="https://chromium.googlesource.com/chromium/blink/+/master/Source/devtools/front_end/emulated_devices/module.json" rel="nofollow noreferrer">source code</a> Iphone 6 already defined with 'divided' size and pixelRatio 2.0</p>
  
  <pre><code>"title": "Apple iPhone 6",
              "screen": {
                  "horizontal": {
                      "width": 667,
                      "height": 375
                  },
                  "device-pixel-ratio": 2,
                  "vertical": {
                      "width": 375,
                      "height": 667
                  }
  </code></pre>
  
  <p>Here is sample of my enum for mobile devices.</p>
  
  <pre><code>public enum ChromeMobileDevice {
     IPHONE_8(1334, 750, 2.0, "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1"),
     IPHONE_XS_MAX(2688, 1242, 3.0, "Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/69.0.3497.105 Mobile/15E148 Safari/605.1"),
     GALAXY_S8(2960, 1440, 4.0, "Mozilla/5.0 (Linux; Android 7.0; SM-G892A Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/60.0.3112.107 Mobile Safari/537.36"),
     IPAD_MINI(2048, 1536, 2.0, "Mozilla/5.0 (iPad; CPU OS 12_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1"),
     GALAXY_TAB_10_1(1920, 1200, 1.0, "Mozilla/5.0 (Linux; Android 8.1.0; SM-T580) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36");
  
     private int height;
     private int width;
     private double pixelRatio;
     private String userAgent;
     private boolean touch = false;
  
     private ChromeMobileDevice(int height, int width, double pixelRatio, String userAgent) {
        this.height = height;
        this.width = width;
        this.pixelRatio = pixelRatio;
        this.userAgent = userAgent;
     }
  
     public static ChromeMobileDevice getByName(final String chromeMobileDeviceName) {
        return Stream.of(ChromeMobileDevice.values()).filter(b -&gt; b.name().equalsIgnoreCase(chromeMobileDeviceName)).findAny()
              .orElseThrow(() -&gt; new IllegalArgumentException(String.format("Unsupported chrome emulator name: %s", chromeMobileDeviceName)));
     }
  
     public HashMap&lt;String, Object&gt; getPortraitDeviceMetrics() {
        return Maps.newHashMap(ImmutableMap.of(
              "height", height,
              "width", width,
              "pixelRatio", pixelRatio,
              "touch", touch));
     }
  
     public HashMap&lt;String, Object&gt; getLandscapeDeviceMetrics() {
        return Maps.newHashMap(ImmutableMap.of(
              "width", height,
              "height", width,
              "pixelRatio", pixelRatio,
              "touch", touch));
     }
  }
  </code></pre>
  
  <p><strong>UPD</strong>
  Sample of chromedriver creation</p>
  
  <pre><code>ChromeOptions capabilities = new ChromeOptions();
  capabilities.setCapability("chrome.switches", "disable-extensions");
  capabilities.setCapability(SUPPORTS_JAVASCRIPT, true);
  capabilities.addArguments("--hide-scrollbars");
  capabilities.addArguments("--allow-running-insecure-content");
  capabilities.addArguments("--start-maximized");
  capabilities.addArguments("--disable-infobars");
  
  Map&lt;String, Object&gt; mobileEmulation = new HashMap&lt;&gt;();
  ChromeMobileDevice chromeMobileDevice = ChromeMobileDevice.getByName(chromeMobileEmulation.get());
  mobileEmulation.put("userAgent", chromeMobileDevice.getUserAgent());
  mobileEmulation.put("deviceMetrics", chromeMobileDevice.getPortraitDeviceMetrics());
  
  capabilities.setExperimentalOption("mobileEmulation", mobileEmulation);
  WebDriver driver = new ChromeDriver(capabilities );
  </code></pre>