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

Puppeteer is a dev dep and cant be required #24

Merged
merged 2 commits into from
Jun 17, 2024
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
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 @@ -31,7 +30,7 @@
});
console.log(`Puppeteer visited page located at ${pdfGenerationRequest.url}`);
const options = { ...htmlToPdfPrintOptions, ...pdfGenerationRequest.pdfOptions };
await report.pdfPage(page as any, {

Check warning on line 33 in src/services/pdf-generation.ts

View workflow job for this annotation

GitHub Actions / Tests

Unexpected any. Specify a different type
path: pdfGenerationRequest.localFilePath,
...options
});
Expand All @@ -42,15 +41,18 @@
}

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);
}
}
Loading