From 8cef94879cb0456874fcb8f17d04bb4d108357ce Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Mon, 19 Jul 2021 09:42:04 -0500 Subject: [PATCH] feat(BREAKING): Set DPR to 1 for Chrome headless browsers by default (#17377) --- packages/server/lib/browsers/chrome.ts | 4 ++++ packages/server/test/e2e/5_headless_spec.ts | 6 ++++++ .../cypress/integration/device_pixel_ratio.spec.js | 6 ++++++ .../fixtures/projects/screen-size/cypress/plugins/index.js | 1 + packages/server/test/unit/browsers/chrome_spec.js | 3 ++- 5 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 packages/server/test/support/fixtures/projects/screen-size/cypress/integration/device_pixel_ratio.spec.js diff --git a/packages/server/lib/browsers/chrome.ts b/packages/server/lib/browsers/chrome.ts index 4ccebd83d798..9bb29a4f4182 100644 --- a/packages/server/lib/browsers/chrome.ts +++ b/packages/server/lib/browsers/chrome.ts @@ -429,6 +429,10 @@ export = { // set default headless size to 1920x1080 // https://github.com/cypress-io/cypress/issues/6210 args.push('--window-size=1920,1080') + + // set default headless DPR to 1 + // https://github.com/cypress-io/cypress/issues/17375 + args.push('--force-device-scale-factor=1') } // force ipv4 diff --git a/packages/server/test/e2e/5_headless_spec.ts b/packages/server/test/e2e/5_headless_spec.ts index 8366e021ac4c..264adffb61fd 100644 --- a/packages/server/test/e2e/5_headless_spec.ts +++ b/packages/server/test/e2e/5_headless_spec.ts @@ -84,4 +84,10 @@ describe('e2e headless', function () { project: Fixtures.projectPath('screen-size'), spec: 'default_size.spec.js', }) + + e2e.it('launches at DPR 1x', { + headed: false, + project: Fixtures.projectPath('screen-size'), + spec: 'device_pixel_ratio.spec.js', + }) }) diff --git a/packages/server/test/support/fixtures/projects/screen-size/cypress/integration/device_pixel_ratio.spec.js b/packages/server/test/support/fixtures/projects/screen-size/cypress/integration/device_pixel_ratio.spec.js new file mode 100644 index 000000000000..2892299130a8 --- /dev/null +++ b/packages/server/test/support/fixtures/projects/screen-size/cypress/integration/device_pixel_ratio.spec.js @@ -0,0 +1,6 @@ +describe('devicePixelRatio', () => { + it('has DPR of 1', () => { + // assert the browser was spawned with DPR of 1 + expect(window.devicePixelRatio).to.equal(1) + }) +}) diff --git a/packages/server/test/support/fixtures/projects/screen-size/cypress/plugins/index.js b/packages/server/test/support/fixtures/projects/screen-size/cypress/plugins/index.js index c766ef4b2314..3f555935d8e7 100644 --- a/packages/server/test/support/fixtures/projects/screen-size/cypress/plugins/index.js +++ b/packages/server/test/support/fixtures/projects/screen-size/cypress/plugins/index.js @@ -4,6 +4,7 @@ module.exports = (on) => { on('before:browser:launch', (browser, options) => { // options.args.push('-width', '1280', '-height', '1024') + // options.args.push('--force-device-scale-factor=2') // return options }) diff --git a/packages/server/test/unit/browsers/chrome_spec.js b/packages/server/test/unit/browsers/chrome_spec.js index 355431af1704..27f6a18edd1f 100644 --- a/packages/server/test/unit/browsers/chrome_spec.js +++ b/packages/server/test/unit/browsers/chrome_spec.js @@ -99,7 +99,7 @@ describe('lib/browsers/chrome', () => { }) }) - it('sets default window size in headless mode', function () { + it('sets default window size and DPR in headless mode', function () { chrome._writeExtension.restore() return chrome.open({ isHeadless: true, isHeaded: false }, 'http://', {}, this.automation) @@ -109,6 +109,7 @@ describe('lib/browsers/chrome', () => { expect(args).to.include.members([ '--headless', '--window-size=1920,1080', + '--force-device-scale-factor=1', ]) }) })