Update the Docker config to support headless Chrome

This commit is contained in:
Matt Isenhower 2017-09-20 11:06:32 -07:00
parent 3daa26d1fc
commit 01a5b98a2b
3 changed files with 23 additions and 5 deletions

View File

@ -3,8 +3,6 @@ version: '2'
services:
app:
image: node:8
build: docker/app
volumes:
- ./:/app
working_dir: /app
command: 'yarn cron'

14
docker/app/Dockerfile Normal file
View File

@ -0,0 +1,14 @@
FROM node:8
# Headless Chrome config
# From: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#running-puppeteer-in-docker
# Install latest chrome (dev) package.
# Note: this also installs the necessary libs so we don't need the previous RUN command.
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - &&\
sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' &&\
apt-get update &&\
apt-get install -y google-chrome-unstable
WORKDIR /app
CMD ["yarn", "cron"]

View File

@ -13,7 +13,10 @@ const viewport = {
async function captureScreenshot(options) {
// Launch a new Chrome instance
const browser = await puppeteer.launch({
args: ['--disable-web-security'], // This allows us to retrieve file:// URLs via JS
args: [
'--disable-web-security', // This allows us to retrieve file:// URLs via JS
'--no-sandbox', // Allow running as root inside the Docker container
],
// headless: false, // For testing
});
@ -22,7 +25,10 @@ async function captureScreenshot(options) {
page.setViewport(viewport);
// Navigate to the URL
await page.goto(options.url);
await page.goto(options.url, {
waitUntil: 'networkidle', // Wait until the network is idle
networkIdleTimeout: 500, // 500ms
});
// Take the screenshot
let result = await page.screenshot();