puppeteer

📅 2017-09-01

chromescreenshottools

国内下载puppeteer可能会出现timeout问题,建议使用cnpm

  1. GoogleChromeLabs/puppeteer-examples: Use case-driven examples for using Puppeteer and headless chrome
  2. GoogleChrome/puppeteer: Headless Chrome Node API
  3. Capture DOM element screenshot using Chrome headless: 针对给定dom节点截图
  4. emadehsan/thal: Getting started with Puppeteer and Chrome Headless for Web Scraping
  5. Automating Google Chrome with Node.js
  6. alvarcarto/url-to-pdf-api: Web page PDF rendering done right. Self-hosted service for rendering receipts, invoices, or any content.
  7. Efficiently snapshotting your single-page-apps with Puppeteer: 涉及到将puppeteer放在对象池中以及缓存之前生成的图片
  8. transitive-bullshit/awesome-puppeteer: A curated list of awesome puppeteer resources.
# 查询打开的页面
curl http://192.168.8.29:6666/json

# 查询guid
http://192.168.8.29:6666/json/version

解决ubuntu上中文乱码的问题

sudo apt-get install language-pack-zh*
sudo apt-get install fonts-arphic-ukai fonts-arphic-uming fonts-ipafont-mincho\
fonts-ipafont-gothic fonts-unfonts-core

## emoji 乱码
sudo add-apt-repository ppa:eosrei/fonts
sudo apt update && sudo apt install fonts-emojione-svginot

解决centos上的中文乱码问题

yum groupinstall "fonts"

启动失败问题

# node_modules/puppeteer/.local-chromium/linux-722234/chrome-linux
chown root:root chrome_sandbox && sudo chmod 4755 chrome_sandbox && \
    export CHROME_DEVEL_SANDBOX="$PWD/chrome_sandbox"

bind all interfaces

// 只在headless模式下有效
puppeteer.launch({
  args: [
    '--remote-debugging-address=0.0.0.0',
    '--remote-debugging-port=6666'
  ]
});

CentOS Linux release 7.5.1804安装依赖

yum install git
  
yum install ipa-gothic-fonts xorg-x11-fonts-100dpi xorg-x11-fonts-75dpi xorg-x11-utils xorg-x11-fonts-cyrillic xorg-x11-fonts-Type1 xorg-x11-fonts-misc -y
yum groupinstall "fonts"

yum install libXcomposite libXcursor libXdamage libcups cups -y
yum install libX11-devel libXScrnSaver pango atk at-spi2-atk gtk3 -y

cd node_modules/puppeteer/.local-chromium/linux-536395/chrome-linux
chown root:root chrome_sandbox && sudo chmod 4755 chrome_sandbox

阿里云安装puppeteer依赖时,其镜像可能报404

/etc/apt/sources.list的内容替换为如下:

deb http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse

deb http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse

然后执行:

apt-get update
apt-get install libpangocairo-1.0-0 libx11-xcb1 libxcomposite1 libxcursor1 libxdamage1 libxi6 libxtst6 libnss3 libcups2 libxss1 libxrandr2 libgconf2-4 libasound2 libatk1.0-0 libgtk-3-0
Edit