node.js - Docker + WebGL + Headless Chrome 错误 : Pa

我想用这样的 3D Canvas 截取网页的屏幕截图:

import {createServer} from 'http'
import puppeteer from 'puppeteer'

const url = "https://webglfundamentals.org/webgl/webgl-load-obj-w-extents.html";

async function main() {
const browser = await puppeteer.launch({
  args: [
    "--no-sandbox",
    "--use-gl=swiftshader",
    "--enable-webgl",
  ],
  headless: true,
  dumpio: true,
  defaultViewport: { width: 400, height: 300 },
});

const page = await browser.newPage();

await page.goto(url);
await page.waitForNetworkIdle();

await page.waitForSelector("#canvas");

const screenshot = await page.screenshot();
console.log(screenshot);

在本地运行代码,在我的 Ubuntu 机器上工作正常,生成此图像:

在 Docker 容器 ( Ubuntu + Node.js + Chrome ) 中运行代码不起作用。 它会截取屏幕截图,但不会呈现 3D Canvas 。

[end of stack trace]
[0927/180308.980024:ERROR:gpu_process_host.cc(961)] GPU process exited unexpectedly: exit_code=134
[0927/180308.980054:WARNING:gpu_process_host.cc(1274)] The GPU process has crashed 6 time(s)
[0927/180308.982162:ERROR:gpu_init.cc(441)] Passthrough is not supported, GL is disabled
[0927/180308.983772:WARNING:gpu_process_host.cc(989)] Reinitialized the GPU process after a crash. The reported initialization time was 0 ms

可以在此处找到该问题的最小复现:https://github.com/flolu/docker-puppeteer-webgl


我的目标是在 Kubernetes 集群上运行代码。如何配置我的 Dockerfile 以支持 WebGL?

最佳答案

解决方案是向我的 Dockerfile 添加一些依赖项:

RUN apt-get install -y xorg xserver-xorg xvfb libx11-dev libxext-dev

工作示例:https://github.com/flolu/docker-puppeteer-webgl

关于node.js - Docker + WebGL + Headless Chrome 错误 : Passthrough is not supported, GL 被禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69351416/

相关文章:

python - 如何根据最大值将字典中的所有值分配给变量

nestjs - 嵌套类验证器 minDate 即使日期更大也会抛出错误

javascript - 正则表达式获取第一次和最后一次出现之间的子字符串

c++ - 在 C++ 中的 unordered_map 中排序

c# - 从 C# 中的 Win32_PnPEntity 获取 DEVPKEY_Device_Bus

python - 如何确定 Pandas DataFrame 中给定 x 和 y 坐标列的象限

visual-studio - 缺少 Visual Studio 性能探查器

php - 无法加载 Mac M1 SQL Server SQLSrv OpenSSL 库,请确保已

python - 在不添加额外列的情况下创建颜色基于年份的散点图

kotlin-coroutines - Kotest 与 kotlinx-coroutines-te