Skip to content

Commit

Permalink
Merge pull request #618 from marp-team/chrome-disable-gpu-env
Browse files Browse the repository at this point in the history
Allow to disable GPU use of Chrome through `CHROME_DISABLE_GPU` environment variable
  • Loading branch information
yhatt authored Nov 6, 2024
2 parents 4087799 + 6125f35 commit 99b4e36
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Added

- Allow to disable GPU use of Chrome through `CHROME_DISABLE_GPU` environment variable ([#592](https://github.com/marp-team/marp-cli/issues/592), [#617](https://github.com/marp-team/marp-cli/issues/617), [#618](https://github.com/marp-team/marp-cli/pull/618))

## v4.0.2 - 2024-10-31

### Fixed
Expand Down
7 changes: 7 additions & 0 deletions src/browser/browsers/chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class ChromeBrowser extends Browser {
])

if (!(await this.puppeteerArgsEnableSandbox())) args.add('--no-sandbox')
if (!this.puppeteerArgsEnableGPU()) args.add('--disable-gpu')

return [...args]
}
Expand All @@ -95,6 +96,12 @@ export class ChromeBrowser extends Browser {
return true
}

private puppeteerArgsEnableGPU() {
if (process.env.CHROME_DISABLE_GPU) return false

return true
}

private async puppeteerPipe() {
if (await isWSL()) return false
if (await isSnapBrowser(this.path)) return false
Expand Down
15 changes: 14 additions & 1 deletion test/browser/browsers/chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,20 @@ describe('ChromeBrowser', () => {
})
})

describe('Disable extensions', () => {
describe('Disabling GPU', () => {
it('adds --disable-gpu argument if CHROME_DISABLE_GPU environment variable is defined', async () => {
process.env.CHROME_DISABLE_GPU = '1'
await new ChromeBrowser({ path: '/path/to/chrome' }).launch()

expect(puppeteer.launch).toHaveBeenCalledWith(
expect.objectContaining({
args: expect.arrayContaining(['--disable-gpu']),
})
)
})
})

describe('Disabling extensions', () => {
it('ignores --disable-extensions argument if CHROME_ENABLE_EXTENSIONS environment variable is defined', async () => {
process.env.CHROME_ENABLE_EXTENSIONS = '1'
await new ChromeBrowser({ path: '/path/to/chrome' }).launch()
Expand Down

0 comments on commit 99b4e36

Please sign in to comment.