diff --git a/README.md b/README.md index 177927d..ae2b136 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/src/services/pdf-generation.ts b/src/services/pdf-generation.ts index f40199f..c36e0d1 100644 --- a/src/services/pdf-generation.ts +++ b/src/services/pdf-generation.ts @@ -1,4 +1,3 @@ -import { executablePath } from 'puppeteer'; import puppeteer, { PDFOptions } from 'puppeteer-core'; import report from 'puppeteer-report'; @@ -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); } }