Skip to main content

DISPLAY và DNS puppeteer trên vagrant virtualbox

Lỗi thường gặp:

  • Missing X server or $DISPLAY
  • Unable to open X display
  • Could not find Chrome (ver....)
npm install puppeteer

sudo apt-get install libnss3-dev

sudo apt-get install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget libgbm-dev

sudo apt-get install -y xvfb

sudo apt-get -y install xorg xvfb gtk2-engines-pixbuf
sudo apt-get -y install dbus-x11 xfonts-base xfonts-100dpi xfonts-75dpi xfonts-cyrillic xfonts-scalable

sudo apt-get -y install imagemagick x11-apps

Xvfb -ac :99 -screen 0 1280x1024x16 &
export DISPLAY=:99

Lỗi DNS error:

  • ERR! code EAI_AGAIN
  • ERR! request to https://registry.npmjs.org/puppeteer failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org
npm config rm proxy
npm config rm https-proxy --tried removing npm proxy
sudo vi /etc/resolv.conf

Điền thêm dns name resolver vào, bên dưới nameserver đầu tiên:

nameserver 127.0.0.53
nameserver 192.168.1.11

options edns0 trust-ad

Ref:

https://stackoverflow.com/questions/60304251/unable-to-open-x-display-when-trying-to-run-google-chrome-on-centos-rhel-7-5