2017-09-09 98 views
0

我試圖在Heroku,GAE flex,Digital Ocean和Vultr上運行谷歌瀏覽器木偶遊戲,但在我使用puppeteer的路線上,實例只是掛起與502錯誤我用這個簡單的代碼:在Vultr,Digital Ocean,Heroku或GAE上運行谷歌Chrome木偶遊戲

var express = require('express'); 
var router = express.Router(); 
const puppeteer = require('puppeteer'); 

router.get('/', function(req, res, next) { 
    (async() => { 
     const browser = await puppeteer.launch(); 
     const page = await browser.newPage(); 
     await page.goto('http://example.com'); 
     await page.screenshot({path: 'example.png'}); 

     browser.close(); 
     res.send('screen grabbed'); 
    })(); 
}); 

module.exports = router; 

我知道的木偶與節點6現在的工作,但我設置package.json如下:

{ 
    "name": "puppeteer", 
    "version": "0.0.0", 
    "private": true, 
    "scripts": { 
    "start": "node ./bin/www", 
    "deploy": "gcloud app deploy --version dev" 
    }, 
    "engines": { 
    "node": "8.4.0" 
    }, 
    "dependencies": { 
    "body-parser": "~1.17.1", 
    "cookie-parser": "~1.4.3", 
    "debug": "~2.6.3", 
    "express": "~4.15.2", 
    "morgan": "~1.8.1", 
    "pug": "~2.0.0-beta11", 
    "puppeteer": "^0.10.2", 
    "serve-favicon": "~2.4.2" 
    } 
} 

在Vultr的Ubuntu 16.04 64位,我得到出現以下錯誤:

Error: Failed to launch chrome!

/root/mysite/node_modules/puppeteer/.local-chromium/linux-497674/chrome-linux/chrome: error while loading shared libraries: libpangocairo-1.0.so.0: cannot open shared object file: No such file or directory

回答

4

我解決了確保,如果不進行安裝的木偶以下依賴性:

安裝了所有的依賴

sudo apt-get install 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 

然後ARGS傳遞給木偶啓動命令,像這樣:

(async() => { 

const browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']}); 
const page = await browser.newPage(); 
await page.goto('http://example.com'); 
await page.screenshot({path: 'example.png'}); 
res.send('screen grabbed'); 
browser.close(); 
})(); 
相關問題