Puppeteer application error calling chromium within lxc

ubuntu@ip-10-10-10-81:~/node-test$ lxc list
To start your first container, try: lxc launch ubuntu:22.04
Or for a virtual machine: lxc launch ubuntu:22.04 --vm

±-------------±--------±--------------------±----------------------------------------------±----------±----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
±-------------±--------±--------------------±----------------------------------------------±----------±----------+
| my-container | RUNNING | 10.48.229.84 (eth0) | fd42:24e5:1974:fbe5:216:3eff:fe9b:c5da (eth0) | CONTAINER | 0 |
±-------------±--------±--------------------±----------------------------------------------±----------±----------+

test@my-container:~/test-node$ uname -a

Linux my-container 6.2.0-1017-aws #17~22.04.1-Ubuntu SMP Fri Nov 17 21:19:35 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux

I’m working on calling the Chrome browser using puppeteer.
Existing applications run correctly on instances other than lxc containers with the same server specifications.
Applications uploaded within the Lxc container cannot be called and an error occurs.

When I created an LXC container, I created the container by default.
Is there anything that needs to be done in LXC, such as security or configuration?
I just got started with LXC.

Below is the result of running the test application.
test@my-container:~/test-node$ node bin/app.js

Puppeteer old Headless deprecation warning:
In the near future headless: true will default to the new Headless mode
for Chrome instead of the old Headless implementation. For more
information, please see Le mode sans interface graphique de Chrome bénéficie d'une amélioration : --headless=new  |  Chromium  |  Chrome for Developers.
Consider opting in early by passing headless: "new" to puppeteer.launch()
If you encounter any bugs, please report them to Sign in to GitHub · GitHub.

file:///home/test/test-node/node_modules/@puppeteer/browsers/lib/esm/launch.js:258
reject(new Error([
^

Error: Failed to launch the browser process!

TROUBLESHOOTING: Troubleshooting | Puppeteer

at Interface.onClose (file:///home/test/test-node/node_modules/@puppeteer/browsers/lib/esm/launch.js:258:24)
at Interface.emit (node:events:526:35)
at Interface.close (node:internal/readline/interface:527:10)
at Socket.onend (node:internal/readline/interface:253:10)
at Socket.emit (node:events:526:35)
at endReadableNT (node:internal/streams/readable:1408:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v20.9.0

The source is no different. It’s just a default test.
import * as puppeteer from ‘puppeteer’;

var product : puppeteer.Product = ‘chrome’;

const options = {
product: product,
headless: true,
//executablePath: ‘/usr/bin/chromium-browser’,
executablePath: ‘/snap/bin/chromium’,
ignoreHTTPSErrors: true,
args: [‘–enable-logging=stderr’, ‘–v=1’, ‘–disable-dev-shm-usage’, ‘–no-sandbox’],
};

const browser = await puppeteer.launch(options);
const htmlContent = <body> <h1> Test </h1> </body>;
try {
const page = await browser.newPage();
await page.setViewport({width: 800, height: 1200});
await page.setContent(htmlContent, {waitUntil: ‘networkidle0’});

let pdf = await page.pdf();
console.log(pdf);
await browser.close();

} catch (e) {
console.log(e);
} finally {
try {
await browser.close();
} catch (e) {
console.log(e);
}
}

Hi and welcome!

In this forum we provide support for Incus, which is a continuation of LXD.
See Migrating from LXD and Migrating to Incus from LXD.

Having said that, here is how I install and use Puppeteer with Incus.
In summary

  1. I use a container from the images: repository. It’s the images:ubuntu/22.04/cloud container image.
  2. I get a non-root shell into the container.
  3. I install NVM which is a recommended installer for Node.
  4. In install the latest version of Node as provided by NVM.
  5. I install puppeteer with npm.
  6. The Chrome binary from Puppeteer requires certain GUI libraries to exist in the container. I provide the list and I install all of the required libraries in one go.
  7. I create an example with Puppeteer (the screenshot example) and I run it successfully with headless Chrome. Note that when you initialize the Puppeteer object, the new way is to use headless: new. Otherwise you get a warning that the old way is deprecated.
$ incus launch images:ubuntu/22.04/cloud puppeteer
Creating puppeteer
Starting puppeteer
$ incus exec puppeteer -- sudo --login --user ubuntu
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ubuntu@puppeteer:~$ sudo apt update
...
ubuntu@puppeteer:~$ sudo apt install -y curl
...
ubuntu@puppeteer:~$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
...
=> Downloading nvm as script to '/home/ubuntu/.nvm'

=> Appending nvm source string to /home/ubuntu/.bashrc
=> Appending bash_completion source string to /home/ubuntu/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

ubuntu@puppeteer:~$ logout
$ incus exec puppeteer -- sudo --login --user ubuntu
ubuntu@puppeteer:~$ nvm install node
Downloading and installing node v21.6.1...
Downloading https://nodejs.org/dist/v21.6.1/node-v21.6.1-linux-x64.tar.gz...
############################################################################################################################################################################################################ 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v21.6.1 (npm v10.2.4)
Creating default alias: default -> node (-> v21.6.1)
ubuntu@puppeteer:~$ npm install puppeteer

added 111 packages in 32s

9 packages are looking for funding
  run `npm fund` for details
npm notice 
npm notice New minor version of npm available! 10.2.4 -> 10.3.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.3.0
npm notice Run npm install -g npm@10.3.0 to update!
npm notice 
ubuntu@puppeteer:~$ sudo apt install -y libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libpango-1.0-0 libcairo2 libasound2
...
ubuntu@puppeteer:~$ mkdir screenshot
ubuntu@puppeteer:~$ cd screenshot/
ubuntu@puppeteer:~/screenshot$ cat > index.js
/**
 * @license
 * Copyright 2017 Google Inc.
 * SPDX-License-Identifier: Apache-2.0
 */

'use strict';

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({headless: 'new'});
  const page = await browser.newPage();
  await page.goto('http://example.com');
  await page.screenshot({path: 'example.png'});
  await browser.close();
})();
ubuntu@puppeteer:~/screenshot$ node index.js 
ubuntu@puppeteer:~/screenshot$ ls -l
total 28
-rw-rw-r-- 1 ubuntu ubuntu 27040 Jan 24 14:14 example.png
-rw-rw-r-- 1 ubuntu ubuntu   382 Jan 24 14:07 index.js
ubuntu@puppeteer:~/screenshot$ 

All these are fine when you go headless. If, however, you want to open the chrome window and have it appear on your desktop, that is also achievable.

Blog post, How to install and use Puppeteer in an Incus container – Mi blog lah!

Thank you very much for your guide.
However, the content seems a little different from mine.

It works fine on my x64 system.
If I create a container with lxc on the current x64 system and test it, it works fine.

However, the problem occurs in the aarch64 system. I felt like puppeteer or chromium browser did not work on the aarch64 system, so I performed the test as follows.

I tested it by installing puppeteer and chromium on the aws instance of the aarch64 system and it worked well.

I created an lxc container on the aarch64 system, installed puppeteer and chromium, and tested it, but it did not work properly.

Below is an example of running chromium for debugging. The difference from the normal operating part is
This is device-related matching as shown below. There is no such content in instances created with lxc.
‘DEBUG: device /sys/devices/virtual/dma_heap/system has matching current tag
DEBUG: get bpf object at path /sys/fs/bpf/snap/snap_chromium_chromium
DEBUG: found existing device map’

When running chromium with snap debugging:
test@my-container:~$ LANG=C SNAPD_DEBUG=1 snap run chromium -v --no-sandbox --headless=true

2024/01/24 20:35:45.191518 tool_linux.go:204: DEBUG: restarting into “/snap/snapd/current/usr/bin/snap”

2024/01/24 20:35:45.205020 logger.go:93: DEBUG: – snap startup {“stage”:“start”, “time”:“1706128545.205014”}

2024/01/24 20:35:45.213543 logger.go:93: DEBUG: executing snap-confine from /snap/snapd/20674/usr/lib/snapd/snap-confine

2024/01/24 20:35:45.218816 logger.go:93: DEBUG: SELinux not enabled

2024/01/24 20:35:45.220084 logger.go:93: DEBUG: creating transient scope snap.chromium.chromium

2024/01/24 20:35:45.220888 logger.go:93: DEBUG: using session bus

2024/01/24 20:35:45.222664 logger.go:93: DEBUG: create transient scope job: /org/freedesktop/systemd1/job/45

2024/01/24 20:35:45.240126 logger.go:93: DEBUG: job result is “done”

2024/01/24 20:35:45.240174 logger.go:93: DEBUG: transient scope snap.chromium.chromium-1cdfefdf-288e-4a72-baba-6c7b04e289fe.scope created

2024/01/24 20:35:45.240698 logger.go:93: DEBUG: waited 19.724133ms for tracking

2024/01/24 20:35:45.240736 logger.go:93: DEBUG: – snap startup {“stage”:“snap to snap-confine”, “time”:“1706128545.240732”}

DEBUG: – snap startup {“stage”:“snap-confine enter”, “time”:“1706128545.243317”}

DEBUG: umask reset, old umask was 02

DEBUG: security tag: snap.chromium.chromium

DEBUG: executable: /usr/lib/snapd/snap-exec

DEBUG: confinement: non-classic

DEBUG: base snap: core22

DEBUG: ruid: 1001, euid: 0, suid: 0

DEBUG: rgid: 1001, egid: 1001, sgid: 1001

DEBUG: apparmor label on snap-confine is: /snap/snapd/20674/usr/lib/snapd/snap-confine

DEBUG: apparmor mode is: enforce

DEBUG: – snap startup {“stage”:“snap-confine mount namespace start”, “time”:“1706128545.244428”}

DEBUG: creating lock directory /run/snapd/lock (if missing)

DEBUG: set_effective_identity uid:0 (change: no), gid:0 (change: yes)

DEBUG: opening lock directory /run/snapd/lock

DEBUG: set_effective_identity uid:0 (change: no), gid:1001 (change: yes)

DEBUG: opening lock file: /run/snapd/lock/.lock

DEBUG: set_effective_identity uid:0 (change: no), gid:0 (change: yes)

DEBUG: set_effective_identity uid:0 (change: no), gid:1001 (change: yes)

DEBUG: sanity timeout initialized and set for 30 seconds

DEBUG: acquiring exclusive lock (scope (global), uid 0)

DEBUG: sanity timeout reset and disabled

DEBUG: ensuring that snap mount directory is shared

DEBUG: unsharing snap namespace directory

DEBUG: set_effective_identity uid:0 (change: no), gid:0 (change: yes)

DEBUG: set_effective_identity uid:0 (change: no), gid:1001 (change: yes)

DEBUG: releasing lock 5

DEBUG: opened snap-update-ns executable as file descriptor 5

DEBUG: opened snap-discard-ns executable as file descriptor 6

DEBUG: creating lock directory /run/snapd/lock (if missing)

DEBUG: set_effective_identity uid:0 (change: no), gid:0 (change: yes)

DEBUG: opening lock directory /run/snapd/lock

DEBUG: set_effective_identity uid:0 (change: no), gid:1001 (change: yes)

DEBUG: opening lock file: /run/snapd/lock/chromium.lock

DEBUG: set_effective_identity uid:0 (change: no), gid:0 (change: yes)

DEBUG: set_effective_identity uid:0 (change: no), gid:1001 (change: yes)

DEBUG: sanity timeout initialized and set for 30 seconds

DEBUG: acquiring exclusive lock (scope chromium, uid 0)

DEBUG: sanity timeout reset and disabled

DEBUG: initializing mount namespace: chromium

DEBUG: setting up device cgroup

DEBUG: libudev has current tags support

DEBUG: no devices tagged with snap_chromium_chromium, skipping device cgroup setup

DEBUG: forked support process 9666

DEBUG: block device of snap core22, revision 1035 is 0:76

DEBUG: sanity timeout initialized and set for 30 seconds

DEBUG: joining preserved mount namespace for inspection

DEBUG: found base snap device 0:76 on /usr

DEBUG: sanity timeout reset and disabled

DEBUG: DEBUG: preserved mount is not stale, reusing

DEBUG: joined preserved mount namespace chromium

DEBUG: joining preserved per-user mount namespace

DEBUG: unsharing the mount namespace (per-user)

DEBUG: sc_setup_user_mounts: chromium

DEBUG: performing operation: (disabled) use debug build to see details

DEBUG: set_effective_identity uid:0 (change: no), gid:0 (change: yes)

DEBUG: calling snapd tool snap-update-ns

DEBUG: waiting for snapd tool snap-update-ns to terminate

changing apparmor hat to mount-namespace-capture-helper

DEBUG: helper process waiting for command

DEBUG: sanity timeout initialized and set for 30 seconds

DEBUG: requesting changing of apparmor profile on next exec to snap-update-ns.chromium

logger.go:93: DEBUG: current mount entries

logger.go:93: DEBUG: desired mount entries (sorted)

logger.go:93: DEBUG: - /run/user/1001/doc/by-app/snap.chromium /run/user/1001/doc none bind,rw,x-snapd.ignore-missing 0 0

logger.go:93: DEBUG: desiredIDs: map[/run/user/1001/doc:true]

logger.go:93: DEBUG: reuse: map

logger.go:93: DEBUG: processing mount entries

logger.go:93: DEBUG: entry that requires “/run/user/1001”: /run/user/1001/doc/by-app/snap.chromium /run/user/1001/doc none bind,rw,x-snapd.ignore-missing 0 0

logger.go:93: DEBUG: all mimics:

logger.go:93: DEBUG: - /run/user/1001

logger.go:93: DEBUG: adding entry: /run/user/1001/doc/by-app/snap.chromium /run/user/1001/doc none bind,rw,x-snapd.ignore-missing 0 0

logger.go:93: DEBUG: mount entries ordered as they will be applied

logger.go:93: DEBUG: - /run/user/1001/doc/by-app/snap.chromium /run/user/1001/doc none bind,rw,x-snapd.ignore-missing 0 0

DEBUG: snap-update-ns finished successfully

DEBUG: set_effective_identity uid:0 (change: no), gid:1001 (change: yes)

DEBUG: NOT preserving per-user mount namespace

DEBUG: releasing lock 7

DEBUG: sending command 0 to helper process (pid: 9666)

DEBUG: sanity timeout reset and disabled

DEBUG: helper process received command 0DEBUG:

DEBUG: helper process exiting

waiting for response from helper

DEBUG: waiting for the helper process to exit

DEBUG: helper process exited normally

DEBUG: resetting PATH to values in sync with core snap

DEBUG: – snap startup {“stage”:“snap-confine mount namespace finish”, “time”:“1706128545.258794”}

DEBUG: set_effective_identity uid:1001 (change: yes), gid:1001 (change: yes)

DEBUG: creating user data directory: /home/test/snap/chromium/2735

DEBUG: requesting changing of apparmor profile on next exec to snap.chromium.chromium

DEBUG: ruid: 1001, euid: 1001, suid: 0

DEBUG: setting capabilities bounding set

DEBUG: regaining SYS_ADMIN

DEBUG: loading bpf program for security tag snap.chromium.chromium

DEBUG: read 6072 bytes from /var/lib/snapd/seccomp/bpf//snap.chromium.chromium.bin

DEBUG: read 152 bytes from /var/lib/snapd/seccomp/bpf/global.bin

DEBUG: clearing SYS_ADMIN

DEBUG: execv(/usr/lib/snapd/snap-exec, /usr/lib/snapd/snap-exec…)

DEBUG: argv[1] = chromium

DEBUG: argv[2] = -v

DEBUG: argv[3] = --no-sandbox

DEBUG: argv[4] = --headless=true

DEBUG: umask restored to 02

DEBUG: working directory restored to /home/test

DEBUG: – snap startup {“stage”:“snap-confine to snap-exec”, “time”:“1706128545.261558”}

2024/01/24 20:35:45.266731 logger.go:93: DEBUG: – snap startup {“stage”:“snap-exec to app”, “time”:“1706128545.266725”}

[0124/203545.801821:WARNING:bluez_dbus_manager.cc(248)] Floss manager not present, cannot set Floss enable/disable.

[0124/203545.930453:WARNING:sandbox_linux.cc(400)] InitializeSandbox() called with multiple threads in process gpu-process.

I can help you out with Incus. When you run the lxc command, you are not using Incus.

When you run commands like lxc-ls, you use LXC. You get support here.

When you run commands like lxc, you use LXD. I cannot help help.

When you run commands like incus, you use Incus. You get support here. I can even spin up an arm64 VM if required to help you.

ubuntu@ip-10-10-10-81:~$ incus launch images:ca67a84576dc puppeteer
Creating puppeteer
Starting puppeteer

ubuntu@ip-10-10-10-81:~$ incus ls
±---------------±--------±---------------------±----------------------------------------------±----------±----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
±---------------±--------±---------------------±----------------------------------------------±----------±----------+
| my-container | RUNNING | 10.48.229.84 (eth0) | fd42:24e5:1974:fbe5:216:3eff:fe9b:c5da (eth0) | CONTAINER | 0 |
±---------------±--------±---------------------±----------------------------------------------±----------±----------+
| puppeteer | RUNNING | 10.48.229.208 (eth0) | fd42:24e5:1974:fbe5:216:3eff:fe05:5726 (eth0) | CONTAINER | 0 |
±---------------±--------±---------------------±----------------------------------------------±----------±----------+
| puppeteer-test | RUNNING | 10.48.229.236 (eth0) | fd42:24e5:1974:fbe5:216:3eff:fe7d:749b (eth0) | CONTAINER | 0 |

ubuntu@ip-10-10-10-81:~$ incus exec puppeteer – sudo --login --user ubuntu

ubuntu@puppeteer:~$ uname -a

Linux puppeteer 6.2.0-1017-aws #17~22.04.1-Ubuntu SMP Fri Nov 17 21:19:35 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux

ubuntu@puppeteer:~$ sudo apt update
ubuntu@puppeteer:~$ sudo apt install -y curl
ubuntu@puppeteer:~$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 16555 100 16555 0 0 52041 0 --:–:-- --:–:-- --:–:-- 52223
=> Downloading nvm as script to ‘/home/ubuntu/.nvm’

=> Appending nvm source string to /home/ubuntu/.bashrc
=> Appending bash_completion source string to /home/ubuntu/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR=“$HOME/.nvm”
[ -s “$NVM_DIR/nvm.sh” ] && . “$NVM_DIR/nvm.sh” # This loads nvm
[ -s “$NVM_DIR/bash_completion” ] && . “$NVM_DIR/bash_completion” # This loads nvm bash_completion
ubuntu@puppeteer:~$ source .bashrc

ubuntu@puppeteer:~$ nvm install 20.9.0

Downloading and installing node v20.9.0…

Downloading https://nodejs.org/dist/v20.9.0/node-v20.9.0-linux-arm64.tar.gz

#################################################################################################################################### 100.0%

Computing checksum with sha256sum

Checksums matched!

Now using node v20.9.0 (npm v10.1.0)

Creating default alias: default → 20.9.0 (-> v20.9.0)

For aarch64 chromium-browser

ubuntu@puppeteer:~$ sudo vi /etc/apt/sources.list
deb [arch=arm64] http://ports.ubuntu.com/ focal main multiverse universe
deb [arch=arm64] http://ports.ubuntu.com/ focal-security main multiverse universe
deb [arch=arm64] http://ports.ubuntu.com/ focal-backports main multiverse universe
deb [arch=arm64] http://ports.ubuntu.com/ focal-updates main multiverse universe

dpkg option setting
ubuntu@puppeteer:~$ sudo dpkg --print-foreign-architectures

ubuntu@puppeteer:~$ sudo dpkg --add-architecture arm64

ubuntu@puppeteer:~$ sudo dpkg --print-foreign-architectures

apt-get update
ubuntu@puppeteer:~$ sudo apt-get update

** library install **
ubuntu@puppeteer:~/test$ sudo apt install -y libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libpango-1.0-0 libcairo2 libasound2

** xdg-util install **
ubuntu@puppeteer:~/test$ sudo apt install xdg-utils

chromium-browser install **
ubuntu@puppeteer:
~**$ sudo apt install chromium-browser

** Install version check **
ubuntu@puppeteer:~/test$ snap version
snap 2.61.1
snapd 2.61.1
series 16
ubuntu 23.04
kernel 6.2.0-1017-aws
ubuntu@puppeteer:~/test$ snap info chromium
name: chromium
summary: Chromium web browser, open-source version of Chrome
publisher: Canonical✓
store-url: Install chromium on Linux | Snap Store
contact: Bugs : chromium-browser package : Ubuntu
license: unset
description: |
An open-source browser project that aims to build a safer, faster, and more
stable way for all Internet users to experience the web.
commands:

  • chromium.chromedriver
  • chromium
    snap-id: XKEcBqPM06H1Z7zGOdG5fbICuf8NWK5R
    tracking: latest/stable
    refresh-date: today at 02:54 UTC
    channels:
    latest/stable: 120.0.6099.224 2024-01-19 (2735) 166MB -
    latest/candidate: 120.0.6099.224 2024-01-18 (2735) 166MB -
    latest/beta: 120.0.6099.56 2023-12-01 (2709) 166MB -
    latest/edge: 121.0.6129.0 2023-11-18 (2701) 167MB -
    installed: 120.0.6099.224 (2735) 166MB -

** Sample Source **
o Summary

  • Node : 20.9.0

  • TypeScript : 5.2.3
    o source

  • package.json
    {
    “name”: “browser-test”,
    “version”: “1.0.0”,
    “description”: “browser-test”,
    “main”: “app.js”,
    “scripts”: {
    “build”: “tsc”,
    “start”: “node ./bin/app.js”,
    “test”: “echo "Error: no test specified" && exit 1”
    },
    “author”: “Puppeteer Test”,
    “license”: “MIT”,
    “dependencies”: {
    @types/node”: “^20.11.5”,
    “playwright”: “^1.41.0”,
    “puppeteer”: “^21.7.0”,
    “typescript”: “^5.2.3”
    },
    “type”: “module”
    }

  • tsconfig.json
    {
    “compilerOptions”: {
    “outDir”: “./bin”,
    // “baseUrl”: “/”,
    “sourceMap”: true,
    “declaration”: false,
    “moduleResolution”: “node”,
    “emitDecoratorMetadata”: true,
    “experimentalDecorators”: true,
    “target”: “es2022”,
    “lib”: [
    “es2020”,
    “dom”
    ],

    “module”: “es2022”, /* Specify what module code is generated. /
    “rootDir”: “src”, /
    Specify the root folder within your source files. */

    “esModuleInterop”: true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables ‘allowSyntheticDefaultImports’ for type compatibility. /
    “forceConsistentCasingInFileNames”: true, /
    Ensure that casing is correct in imports. */

    /* Type Checking /
    “strict”: false, /
    Enable all strict type-checking options. /
    “skipLibCheck”: true /
    Skip type checking all .d.ts files. */
    }
    }

  • src/app.ts
    import * as puppeteer from ‘puppeteer’;

var product : puppeteer.Product = ‘chrome’;

const options = {
product: product,
headless: true,
executablePath: ‘/usr/bin/chromium-browser’,
//executablePath: ‘/snap/bin/chromium’,
ignoreHTTPSErrors: true,
args: [‘–enable-logging=stderr’, ‘–v=1’, ‘–disable-dev-shm-usage’, ‘–no-sandbox’],
};

const browser = await puppeteer.launch(options);
const htmlContent = <body> <h1> Test </h1> </body>;
try {
const page = await browser.newPage();
await page.setViewport({width: 800, height: 1200});
await page.setContent(htmlContent, {waitUntil: ‘networkidle0’});

let pdf = await page.pdf();
console.log(pdf);
await browser.close();

} catch (e) {
console.log(e);
} finally {
try {
await browser.close();
} catch (e) {
console.log(e);
}
}

o Build
npm install
npm run build
ubuntu@puppeteer:~/test$ npm install
added 114 packages, and audited 115 packages in 21s
9 packages are looking for funding
run npm fund for details
found 0 vulnerabilities
ubuntu@puppeteer:~/test$ npm run build

browser-test@1.0.0 build
tsc

o Execute
node bin/app.js

o Result
ubuntu@puppeteer:~/test$ node bin/app.js

Puppeteer old Headless deprecation warning:
In the near future headless: true will default to the new Headless mode
for Chrome instead of the old Headless implementation. For more
information, please see Le mode sans interface graphique de Chrome bénéficie d'une amélioration : --headless=new  |  Chromium  |  Chrome for Developers.
Consider opting in early by passing headless: "new" to puppeteer.launch()
If you encounter any bugs, please report them to Sign in to GitHub · GitHub.

file:///home/ubuntu/test/node_modules/@puppeteer/browsers/lib/esm/launch.js:258
reject(new Error([
^

Error: Failed to launch the browser process!

TROUBLESHOOTING: Troubleshooting | Puppeteer

at Interface.onClose (file:///home/ubuntu/test/node_modules/@puppeteer/browsers/lib/esm/launch.js:258:24)
at Interface.emit (node:events:526:35)
at Interface.close (node:internal/readline/interface:527:10)
at Socket.onend (node:internal/readline/interface:253:10)
at Socket.emit (node:events:526:35)
at endReadableNT (node:internal/streams/readable:1408:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v20.9.0
ubuntu@puppeteer:~/test$

I tried again after migrating to incus. But it fails with the same result.
For reference, it works correctly on a typical aarch64 ubuntu instance without LXC.

The first suggestion is to use the pre-formatted environment in markdown to show text that is output from the commands. You do that by putting three backticks on a single line, add the text in between, and then end this with another three backticks on a new line. Like this.

an example

I think the issue is that you are actually installing Chromium in Ubuntu for Puppeteer, and Chromium in Ubuntu 20.04 (or newer), is a snap package. Even if you install the DEB package for Chromium, that DEB package is a dummy package and instead installs behind the scenes the snap package of Chromium. You can verify with

$ snap list
Name                         Version                     Rev    Tracking            Publisher           Notes
chromium                     120.0.6099.224              2734   latest/stable       canonical**          -
...

Something that may not be clear, is that Puppeteer comes with a binary of Chromium. When you run npm install puppeteer, this command also installs a version of the chromium browser. It is a specific version of the browser that puppeteer has been tested extensively with.

With Puppeteer you can select an external browser like one from the package manager (chromium or Firefox), though the snap package of such a browser will bring more trouble.

If you really need an external browser and not use the built-in chromium browser from Puppeteer, I suggest to use the Debian container image (images:debian/12). Both the chromium-browser and firefox packages are deb packages; they are not snap packages as is the case with Ubuntu 20.04 or newer.

First of all thank you for your advice.

Puppeteer provides a chrome binary package, but not yet for aarch64.

I installed chromium myself and specified its path in the sources.
I also want to use several debian, etc.
But the server I am currently running is running on Ubuntu.
I am conducting tests to reflect it on the operating server. It’s not going well through.

I also know that if I install chromium-browser, chromium is installed through snap.

What I’m curious about and want to know is that the program does not run on Ubuntu with aarch64 installed in lxc, so whether something like settings in lxc is needed.

While the cloud server is aarch64 and runs Ubuntu, you can create Incus instances with a Linux distribution other than Ubuntu (such as Debian). In Debian the chromium-browser package is not a snap package.

You are getting stuck with this message,

Error: Failed to launch the browser process!

On top of that, you wouldn’t use a browser as a snap package on Puppeteer even if it worked, because the startup times are way longer.

If you absolutely must use a snap, you’re going to at least follow the instructions in Weird snap behavior. It is there but won’t work. I tried a couple of different containers. Will try on my home machines later. Did the snaps break all of a sudden or is it my imagination they worked before in a container? - #2 by stgraber