Skip to content

Commit

Permalink
Merge pull request #550 from marp-team/review-puppeteer-launch-args
Browse files Browse the repository at this point in the history
Review Puppeteer launch args
  • Loading branch information
yhatt authored Sep 23, 2023
2 parents d72ae4f + dfd676e commit faded9f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Support the project configuration file written in TypeScript `marp.config.ts` ([#548](https://github.com/marp-team/marp-cli/pull/548), [#549](https://github.com/marp-team/marp-cli/pull/549))
- `defineConfig` helper for writing typed configuration ([#549](https://github.com/marp-team/marp-cli/pull/549))
- Recognize `CHROME_NO_SANDBOX` env to allow opt-out of the Chrome/Chromium sandbox during conversion explicitly ([#543](https://github.com/marp-team/marp-cli/issues/543), [#550](https://github.com/marp-team/marp-cli/pull/550))

### Changed

Expand Down
13 changes: 4 additions & 9 deletions src/utils/puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,11 @@ export const generatePuppeteerDataDirPath = async (
export const generatePuppeteerLaunchArgs = async () => {
const args = new Set<string>(['--export-tagged-pdf', '--test-type'])

// Docker environment and WSL environment need to disable sandbox. :(
if (isInsideContainer() || (await isWSL())) args.add('--no-sandbox')
// Docker environment and WSL environment always need to disable sandbox
if (process.env.CHROME_NO_SANDBOX || isInsideContainer() || (await isWSL()))
args.add('--no-sandbox')

// Workaround for Chrome 73 in docker and unit testing with CircleCI
// https://github.com/GoogleChrome/puppeteer/issues/3774
if (isInsideContainer() || process.env.CI)
args.add('--disable-features=VizDisplayCompositor')

// Enable View transitions API
if (!process.env.CI) args.add('--enable-blink-features=ViewTransition')
args.add('--enable-blink-features=ViewTransition')

// LayoutNG Printing
if (process.env.CHROME_LAYOUTNG_PRINTING)
Expand Down
14 changes: 12 additions & 2 deletions test/utils/puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,25 @@ describe('#generatePuppeteerLaunchArgs', () => {
}
})

it('uses specific settings if running within a container image', async () => {
it('disables sandbox if defined CHROME_NO_SANDBOX environment value', async () => {
try {
process.env.CHROME_NO_SANDBOX = '1'

const args = await puppeteerUtils().generatePuppeteerLaunchArgs()
expect(args.args).toContain('--no-sandbox')
} finally {
delete process.env.CHROME_NO_SANDBOX
}
})

it('disables sandbox if running within a container image', async () => {
jest.spyOn(container(), 'isInsideContainer').mockImplementation(() => true)
jest
.spyOn(chromeFinder(), 'findChromeInstallation')
.mockResolvedValue('/usr/bin/chromium')

const args = await puppeteerUtils().generatePuppeteerLaunchArgs()
expect(args.args).toContain('--no-sandbox')
expect(args.args).toContain('--disable-features=VizDisplayCompositor')
})

it("ignores puppeteer's --disable-extensions option if defined CHROME_ENABLE_EXTENSIONS environment value", async () => {
Expand Down

0 comments on commit faded9f

Please sign in to comment.