Skip to content

Commit

Permalink
Update #generatePuppeteerLaunchArgs
Browse files Browse the repository at this point in the history
- Make opt-outable Chrome sandbox by `CHROME_NO_SANDBOX` env
- Review arguments for obsolete Chromium versions
  • Loading branch information
yhatt committed Sep 23, 2023
1 parent d72ae4f commit ac2a03f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
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 ac2a03f

Please sign in to comment.