Skip to content

Commit

Permalink
Enable Puppeteer new headless mode by default
Browse files Browse the repository at this point in the history
  • Loading branch information
yhatt committed Sep 20, 2024
1 parent 78e74b8 commit 07c0007
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/utils/puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ let executablePath: string | undefined | false = false
let wslTmp: string | undefined

export const enableHeadless = (): 'shell' | true =>
process.env.PUPPETEER_HEADLESS_MODE?.toLowerCase() === 'new' ? true : 'shell'
['old', 'legacy', 'shell'].includes(
process.env.PUPPETEER_HEADLESS_MODE?.toLowerCase() ?? ''
)
? 'shell'
: true

const isShebang = (path: string) => {
let fd: number | null = null
Expand Down
17 changes: 15 additions & 2 deletions test/utils/puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ describe('#generatePuppeteerLaunchArgs', () => {
})

describe('with PUPPETEER_HEADLESS_MODE env', () => {
it('uses legacy headless mode if PUPPETEER_HEADLESS_MODE was empty', async () => {
it('uses headless mode if PUPPETEER_HEADLESS_MODE was empty', async () => {
try {
process.env.PUPPETEER_HEADLESS_MODE = ''

const { headless } =
await puppeteerUtils().generatePuppeteerLaunchArgs()

expect(headless).toBe('shell')
expect(headless).toBe(true)
} finally {
delete process.env.PUPPETEER_HEADLESS_MODE
}
Expand Down Expand Up @@ -252,6 +252,19 @@ describe('#generatePuppeteerLaunchArgs', () => {
delete process.env.PUPPETEER_HEADLESS_MODE
}
})

it('uses legacy headless mode if PUPPETEER_HEADLESS_MODE was "shell"', async () => {
try {
process.env.PUPPETEER_HEADLESS_MODE = 'shell'

const { headless } =
await puppeteerUtils().generatePuppeteerLaunchArgs()

expect(headless).toBe('shell')
} finally {
delete process.env.PUPPETEER_HEADLESS_MODE
}
})
})

describe('with CHROME_PATH env in macOS', () => {
Expand Down

0 comments on commit 07c0007

Please sign in to comment.