getBrowser.js 1.1 KB

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