You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Canonical Snap环境中运行基于Puppeteer的Node.js应用时的异常问题排查求助

在Canonical Snap环境中运行基于Puppeteer的Node.js应用时的异常问题排查求助

我开发了一个依赖Puppeteer调用Chromium的Node.js应用,为了打包成Snap格式,我编写了对应的snapcraft.yaml配置,但在构建和运行过程中遇到了两类诡异的问题,折腾了好一阵没找到根源,希望有经验的朋友能帮忙分析一下。

我的snapcraft.yaml配置

---
name: my-node-app
base: core24
version: "0.0.1"
summary: My app
description: |
cannonical app
adopt-info: dist

grade: stable
confinement: devmode

parts:
  my-node-app:
    plugin: nil
    source: .
    build-packages:
      - node-npm
    build-snaps:
      - node/22/stable
    override-build: |
      export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
      export PUPPETEER_SKIP_DOWNLOAD=true
      npm ci && npm run build:node
      mkdir $SNAPCRAFT_PART_INSTALL/distNode
      mkdir $SNAPCRAFT_PART_INSTALL/node_modules
      cp -a distNode/* $SNAPCRAFT_PART_INSTALL/distNode
      cp -a node_modules/* $SNAPCRAFT_PART_INSTALL/node_modules
    stage-snaps:
      - chromium/latest/stable
    stage-packages:
      - libappindicator3-1      
      - ca-certificates
      - fonts-liberation
      - libasound2
      - libasound2-plugins
      - libasound2t64
      - libatspi2.0-0t64
      - libatk-bridge2.0-0
      - libatk1.0-0
      - libc6
      - libcairo2
      - libcups2
      - libdbus-1-3
      - libexpat1
      - libfontconfig1
      - libgbm1
      - libgcc1
      - libglib2.0-0
      - libgtk-3-0
      - libnspr4
      - libnss3
      - 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
      - lsb-release
      - wget
      - xdg-utils
      - libssl-dev
      - gsettings-desktop-schemas
      - libharfbuzz-bin
      - fonts-noto
      - dbus
       
  node:
    plugin: dump
    source: https://nodejs.org/dist/latest/node-v23.10.0-linux-arm64.tar.xz

apps:
  my-node-app:
    command: bin/node $SNAP/distNode/index.js
    plugs: [browser-support, gsettings, home,  password-manager-service,  network, network-bind]
    daemon: simple
    environment:
      LD_LIBRARY_PATH: "$SNAP/usr/lib/chromium-browser/:$SNAP/usr/lib/aarch64-linux-gnu:$LD_LIBRARY_PATH"

Puppeteer启动配置

const browser = await puppeteer.launch({
        executablePath: process.env.SNAP + '/bin/chromium.launcher',
        headless: true,
        dumpio: true,
        userDataDir: process.env.SNAP_DATA,
        args: [
            '--no-sandbox',
            '--disable-setuid-sandbox',
            '--disable-dev-shm-usage',
            '--disable-accelerated-2d-canvas',
            '--disable-gpu',
            '--disable-extensions',
            '--no-zygote',
            '--disable-notifications',
            '--disable-features=WebRtcHideLocalIpsWithMdns',
        ],
    })
    const page = await browser.newPage()
    await page.setViewport({ width: 1920, height: 1080 })

问题1:浏览器能启动但无法访问目标网站,日志输出如下

Server is running on http://localhost:3000
[400316:400341:0327/031850.847874:ERROR:bus.cc(408)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
(process:400316): GLib-GIO-CRITICAL **: 03:18:52.838: g_settings_schema_source_lookup: assertion 'source != NULL' failed
[400316:400316:0327/031853.049242:ERROR:platform_font_skia.cc(255)] Could not find any font: , sans. Falling back to the default

问题2:有时迭代应用代码或修改snapcraft.yaml后,浏览器直接启动失败,报错

error while loading shared libraries: libOSSlib.so: cannot open shared object file: No such file or directory

这两个问题时有时无,实在摸不着头脑,麻烦各位帮忙看看可能的原因,感激不尽!

备注:内容来源于stack exchange,提问作者Solomon Rachamim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.13 20:03:09