Skip to content

Commit

Permalink
feat: locate localy chrome, otherwise install
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiefORZ committed Nov 14, 2023
1 parent 28d40b0 commit 1dffaaa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"debug": "^4.3.4",
"express": "^4.18.2",
"fast-glob": "^3.3.2",
"locate-chrome": "^0.1.1",
"pdf-lib": "^1.17.1",
"puppeteer-chromium-resolver": "^21.0.0",
"puppeteer-core": "^21.5.1",
Expand Down
25 changes: 25 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import glob from 'fast-glob';
import fs from 'fs';
import { lstat, mkdir } from 'fs/promises';
import type { Server } from 'http';
import locateChrome from 'locate-chrome';
import path from 'path';
import { PDFDocument } from 'pdf-lib';
import PCR from 'puppeteer-chromium-resolver';
Expand Down Expand Up @@ -94,9 +95,15 @@ const pdfGenerator = async (args: IArgs) => {
let chromeExecutable = args.chromeExecutable;

if (!chromeExecutable) {
const pcr = await PCR();
chromeExecutable = await pcr.executablePath;
process.env.PUPPETEER_EXECUTABLE_PATH = pcr.executablePath;
const locatedChrome = await locateChrome();
if (locatedChrome) {
chromeExecutable = locatedChrome;
process.env.PUPPETEER_EXECUTABLE_PATH = locatedChrome;
} else {
const pcr = await PCR();
chromeExecutable = await pcr.executablePath;
process.env.PUPPETEER_EXECUTABLE_PATH = pcr.executablePath;
}
}

debug('Launching chrome browser at', chromeExecutable);
Expand Down

0 comments on commit 1dffaaa

Please sign in to comment.