Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NODE_ENV=development
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make development the default and change the conditions to detect the production environment instead? Then we wouldn't need the env file locally.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. That's a nice catch since there are no other envs we can default to dev.

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ npm run dev
<sub><b>Gonçalo Morais</b></sub>
</a>
</td>
<td align="center">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI — this readme section was broken for a while and when we're at it, i'll probably remove it because it doesn't show all contributoes.

Your avatar will still be shown on tiny-helpers.dev though.

image

<a href="https://github.com/realityzero">
<img src="https://avatars.githubusercontent.com/u/33288462?v=4" width="75;" alt="realityzero"/>
<br />
<sub><b>Neshantt</b></sub>
</a>
</td>
</tr>
</table>

44 changes: 33 additions & 11 deletions api/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,40 @@ 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(isDev) {
let options;
console.log('exePath:', exePath);
if (isDev) {
options = {
args: [],
Copy link
Owner

@stefanjudis stefanjudis Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why args and defaultViewport are locally different than in prod?

Ahh. I see — because chromium isn't available. Could we still add --hide-scrollbars and --disable-web-security? 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

executablePath: exePath,
headless: 'new',
};
} else {
options = {
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,
};
}
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 isDevEnv = process.env.NODE_ENV == 'development';
const options = await getOptions(isDevEnv);
return puppeteer.launch(options);
}

async function getPage() {
Expand Down