【问题标题】:Docker + WebGL + Headless Chrome Error: Passthrough is not supported, GL is disabledDocker + WebGL + Headless Chrome 错误:不支持直通,GL 已禁用
【发布时间】:2021-09-28 03:16:00
【问题描述】:

我想用这样的 3D 画布截取网页截图:

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 画布不会渲染。

[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?

【问题讨论】:

    标签: node.js docker webgl puppeteer google-chrome-headless


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-02
      • 2022-12-20
      • 2018-03-16
      • 1970-01-01
      • 2019-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多