Skip to content

Commit

Permalink
Merge pull request #24 from Gavant/bug/puppeteer-dev-dep
Browse files Browse the repository at this point in the history
Puppeteer is a dev dep and cant be required
  • Loading branch information
bakerac4 authored Jun 17, 2024
2 parents 29a57b4 + 1c7abfe commit 50791cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@

Gavant package that handles requests to load an html page and return a pdf using s3.

To run this package locally - `LOCAL_CHROME_PATH` must be provided in the command line i.e.

```
LOCAL_CHROME_PATH="/PATH_TO_ADDON/html-to-pdf/node_modules/puppeteer/.local-chromium/mac-1011831/chrome-mac/Chromium.app/Contents/MacOS/Chromium" yarn test
```

Releases are handled by `release-it` and changelog is automatically generated using `auto-changelog`.
10 changes: 6 additions & 4 deletions src/services/pdf-generation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { executablePath } from 'puppeteer';
import puppeteer, { PDFOptions } from 'puppeteer-core';
import report from 'puppeteer-report';

Expand Down Expand Up @@ -42,15 +41,18 @@ export default class PdfGenerationService {
}

async launchBrowser(pdfGenerationRequest: PdfGenerationRequest) {
const chromiumPath = process.env.IS_LOCAL ? executablePath() : await chromium.executablePath();
const chromiumPath = process.env.LOCAL_CHROME_PATH
? process.env.LOCAL_CHROME_PATH
: await chromium.executablePath();
const options = {
args: process.env.IS_LOCAL ? process.env.BROWSER_ARGS?.split(',') ?? ['--no-sandbox'] : chromium.args,
args: process.env.LOCAL_CHROME_PATH
? process.env.BROWSER_ARGS?.split(',') ?? ['--no-sandbox']
: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: chromiumPath,
headless: chromium.headless as boolean,
...pdfGenerationRequest.browserOptions
};

return await puppeteer.launch(options);
}
}

0 comments on commit 50791cd

Please sign in to comment.