getBrowser.js 938 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* eslint-disable global-require */
  2. const findChrome = require('carlo/lib/find_chrome');
  3. const getBrowser = async () => {
  4. try {
  5. const puppeteer = require('puppeteer');
  6. return await puppeteer.launch({
  7. args: [
  8. '--disable-gpu',
  9. '--disable-dev-shm-usage',
  10. '--no-first-run',
  11. '--no-zygote',
  12. '--no-sandbox',
  13. ],
  14. });
  15. } catch (error) {
  16. // console.log(error)
  17. }
  18. try {
  19. const puppeteer = require('puppeteer-core');
  20. const findChromePath = await findChrome({});
  21. const { executablePath } = findChromePath;
  22. return await puppeteer.launch({
  23. executablePath,
  24. args: [
  25. '--disable-gpu',
  26. '--disable-dev-shm-usage',
  27. '--no-first-run',
  28. '--no-zygote',
  29. '--no-sandbox',
  30. ],
  31. });
  32. } catch (error) {
  33. console.log('🧲 no find chrome');
  34. }
  35. throw new Error('no find puppeteer');
  36. };
  37. module.exports = getBrowser;