diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..9347f80c --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +# production | development +NODE_ENV=production \ No newline at end of file diff --git a/README.md b/README.md index 09fd2cf1..72376008 100644 --- a/README.md +++ b/README.md @@ -252,6 +252,13 @@ npm run dev Gonçalo Morais + + + realityzero +
+ Neshantt +
+ diff --git a/api/screenshot.js b/api/screenshot.js index 50169426..c285f0c1 100644 --- a/api/screenshot.js +++ b/api/screenshot.js @@ -2,18 +2,41 @@ const chromium = require('@sparticuz/chromium-min'); const puppeteer = require('puppeteer-core'); let _page; +// get platform specific chrome executable for local environment +const exePath = process.platform === "win32" + ? "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" + : process.platform === "linux" + ? "/usr/bin/google-chrome" + : "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; + +async function getOptions(isProd) { + let options; + console.log('exePath:', exePath); + const args = [...chromium.args, '--hide-scrollbars', '--disable-web-security']; + if (isProd) { + options = { + args, + defaultViewport: chromium.defaultViewport, + executablePath: await chromium.executablePath( + `https://github.com/Sparticuz/chromium/releases/download/v116.0.0/chromium-v116.0.0-pack.tar` + ), + headless: chromium.headless, + ignoreHTTPSErrors: true, + }; + } else { + options = { + args, + executablePath: exePath, + headless: 'new', + }; + } + return options; +} + async function getBrowser() { - // local development is broken for this đŸ‘‡ - // but it works in vercel so I'm not gonna touch it - return puppeteer.launch({ - args: [...chromium.args, '--hide-scrollbars', '--disable-web-security'], - defaultViewport: chromium.defaultViewport, - executablePath: await chromium.executablePath( - `https://github.com/Sparticuz/chromium/releases/download/v116.0.0/chromium-v116.0.0-pack.tar` - ), - headless: chromium.headless, - ignoreHTTPSErrors: true, - }); + const isProdEnv = process.env.NODE_ENV == 'production'; + const options = await getOptions(isProdEnv); + return puppeteer.launch(options); } async function getPage() {