-
Notifications
You must be signed in to change notification settings - Fork 349
[OPTIMISATION] fetch platform specific chrome image #518
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
base: primary
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
NODE_ENV=development | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,6 +252,13 @@ npm run dev | |
<sub><b>Gonçalo Morais</b></sub> | ||
</a> | ||
</td> | ||
<td align="center"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
<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> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: [], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ahh. I see — because There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
|
There was a problem hiding this comment.
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 theproduction
environment instead? Then we wouldn't need the env file locally.There was a problem hiding this comment.
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.