flo*_*olu 2 webgl node.js docker google-chrome-headless puppeteer
我想使用 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);
Run Code Online (Sandbox Code Playgroud)
在我的 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
Run Code Online (Sandbox Code Playgroud)
可以在这里找到该问题的最小重现:https ://github.com/flolu/docker-puppeteer-webgl
我的目标是在 Kubernetes 集群上运行代码。如何配置我的 Dockerfile 以支持 WebGL?
解决方案是向我的 Dockerfile 添加一些依赖项:
RUN apt-get install -y xorg xserver-xorg xvfb libx11-dev libxext-dev
Run Code Online (Sandbox Code Playgroud)
工作示例: https: //github.com/flolu/docker-puppeteer-webgl
| 归档时间: |
|
| 查看次数: |
3710 次 |
| 最近记录: |