Green Coding Puppeteer Container not running headless browser
hellstromme opened this issue · 4 comments
I've dockerised a test application and I'm trying to get the suggested puppeteer container to work. When I start runner.py I get the following error when it gets to the puppeteer container:
Error: RuntimeError occured in runner.py:
Process '['docker', 'exec', 'puppeteer-container', 'node', '/var/www/puppeteer-flow.js']' had bad returncode: 1. Stderr: /var/www/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:299
reject(new Error([
^
Error: Failed to launch the browser process! spawn /root/.cache/puppeteer/chrome/linux-1069273/chrome-linux/chrome ENOENT
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
at onClose (/var/www/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:299:20)
at ChildProcess.<anonymous> (/var/www/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:293:24)
at ChildProcess.emit (node:events:513:28)
at ChildProcess._handle.onexit (node:internal/child_process:289:12)
at onErrorNT (node:internal/child_process:476:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Node.js v18.12.1
; Detached process: False
Run-ID: d01d513a-9212-4f00-93af-2f21bbb37048
This is my usage scenario:
name: To Do App Test
author: James Camilleri <jcamilleri@scottlogic.com>
description: Scenario to add items to a to do list.
networks:
todo-network:
services:
tododb:
build:
context: .
dockerfile: Dockerfile-mongo
container_name: tododb
image: mongo
restart: always
environment:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=password
- MONGO_INITDB_DATABASE=todo
expose:
- "27017"
ports:
- "27017:27017"
networks:
- todo-network
volumes:
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js
db-admin:
build:
context: .
dockerfile: Dockerfile-mongo-express
container_name: db-admin
image: mongo-express
restart: always
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME=admin
- ME_CONFIG_MONGODB_ADMINPASSWORD=password
- ME_CONFIG_MONGODB_SERVER=tododb
- ME_CONFIG_BASICAUTH_USERNAME=james
- ME_CONFIG_BASICAUTH_PASSWORD=password
expose:
- "8081"
ports:
- "8081:8081"
networks:
- todo-network
depends_on:
- tododb
todo-app:
build:
context: .
dockerfile: Dockerfile-todoapp
container_name: todo-app
image: "node:latest"
user: "node"
working_dir: /home/node/app
expose:
- "3000"
ports:
- "3000:3000"
networks:
- todo-network
depends_on:
- db-admin
command:
"node index.js"
puppeteer-container:
container_name: puppeteer-container
image: greencoding/puppeteer-chrome
setup-commands:
- cp /tmp/repo/test/puppeteer-flow.js /var/www/puppeteer-flow.js
depends_on:
- todo-app
networks:
- todo-network
flow:
- name: Add to do items
container: puppeteer-container
commands:
- type: console
command: node /var/www/puppeteer-flow.js
note: Starting Puppeteer Flow
read-notes-stdout: true
- type: console
command: sleep 30
note: Idling
- type: console
command: node /var/www/puppeteer-flow.js
note: Starting Puppeteer Flow again
read-notes-stdout: true
This is part of my puppeteer file:
const puppeteer = require('puppeteer');
(async () => {
// Launch the browser and open a new blank page
const browser = await puppeteer.launch({
args: [ '--disable-gpu', '--disable-setuid-sandbox', '--no-sandbox', '--headless', ]
});
const page = await browser.newPage();
// Navigate the page to a URL
await page.goto('https://todo-app:3000/');
Do you have any idea why the chrome process is unable to start within the greencoding/puppeteer-chrome image?
What base OS are you running on and what architecture do you have?
We have seen this error before when running puppeteer on a macOS or windows system and/or on a non-x64 architecture.
The base image we provide under greencoding/puppeteer-chrome
is only build for amd64. If you are running an arm system or under macOS / windows I suggest you rather use our Playwright container with python bindings. See an example where we use it here
However you are also free to use any other puppeteer / playwright container. Our tool is agnostic in that.
You should just verify that you can start the puppeteer / playwright with the container normally on your system by entering the container and starting the browser process directly in headless mode.
Hope this helps. Please follow up if not with more details.
Ah, apologies, I should have included that detail.
I'm running Linux Mint 21.2 Cinnamon on an old laptop with a Intel Core 5-4210U CPU @ 1.70GHz. I tried a variety of puppeteer containers and got similar errors.
I gave it a spin. The executable path is not set correctly.
Try this:
puppeteer = require('puppeteer');
(async () => {
// Launch the browser and open a new blank page
const browser = await puppeteer.launch({
executablePath: "/usr/bin/chromium-browser",
args: [ '--disable-gpu', '--disable-setuid-sandbox', '--no-sandbox', '--headless', ]
});
const page = await browser.newPage();
// Navigate the page to a URL
await page.goto('https://todo-app:3000/');
})();
This should at least open the browser. Connecting to the domain I did not check. Hopefully this gets you to the next step.
Yes, that worked - thank you! :)