Skip to content

Commit

Permalink
Merge pull request #593 from marp-team/new-headless-mode
Browse files Browse the repository at this point in the history
Adopt new headless mode by default
  • Loading branch information
yhatt committed Sep 20, 2024
2 parents 78e74b8 + ec1b443 commit 1a03f64
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- Upgrade Marp Core to [v4.0.0](https://github.com/marp-team/marp-core/releases/v4.0.0) ([#591](https://github.com/marp-team/marp-cli/pull/591))
- The slide container of built-in themes became the block element and adopted safe centering
- Relax HTML allowlist: Allowed a lot of HTML elements and attributes by default
- Use [the new headless mode of Chrome](https://developer.chrome.com/docs/chromium/headless) while converting by default ([#593](https://github.com/marp-team/marp-cli/pull/593))
- You can get back to the old headless mode by setting `PUPPETEER_HEADLESS_MODE=old` env.

### Added

Expand Down
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 1a03f64

Please sign in to comment.