Skip to content

Commit

Permalink
feat(BREAKING): Set DPR to 1 for Chrome headless browsers by default (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jennifer-shehane authored Jul 19, 2021
1 parent 97c03c1 commit 8cef948
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/server/lib/browsers/chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions packages/server/test/e2e/5_headless_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})
})
Original file line number Diff line number Diff line change
@@ -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)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
3 changes: 2 additions & 1 deletion packages/server/test/unit/browsers/chrome_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -109,6 +109,7 @@ describe('lib/browsers/chrome', () => {
expect(args).to.include.members([
'--headless',
'--window-size=1920,1080',
'--force-device-scale-factor=1',
])
})
})
Expand Down

0 comments on commit 8cef948

Please sign in to comment.