Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review Puppeteer launch args #550

Merged
merged 2 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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