Running threejs on headless chromium using gpu

Hi all!
I am trying to use threejs on headless chromium using puppeteer(v5.2.1) and gpu acceleration ( Not swiftshader)
However, when trying to run threejs I get black screen.

I wrote simple script to showcase the issue. (Running on mac)

const puppeteer = require('puppeteer');
var os = require('os');

const arguments = process.argv

console.log(arguments)

const pagePath = arguments[2]
const outputName = arguments[3]
const gl = arguments[4]

console.log("Platform: " + os.platform());
console.log("Architecture: " + os.arch());

function getChromeArgs() {
  let args = ['--headless']

  if (gl) {
    args = [
      '--headless',
      `--use-gl=${gl}`]
  }

  return args
}

(async () => {
  console.log(getChromeArgs())
  const browser = await puppeteer.launch({
    args: getChromeArgs(),
    headless: false
  });
  const page = await browser.newPage();
  await page.goto(pagePath);
  await page.screenshot({path: outputName + '.png'});
  await page.pdf({path: outputName + '.pdf'})

  await browser.close();
})();

When running the script with the following command: node puppeteerTest.js https://threejs.org/examples/#webgl_animation_cloth threejs egl
I get black result:

When running node puppeteerTest.js chrome://gpu gpu egl I get that GPU is enabled.

When running with swiftshader everything works fine. also with older version of chromium (v78) it works as well.

Any suggestion what can I do to run threejs on headless chromium using gpu?

Side note: I am using threejs for an entirely different project. The code attached is just to demonstrate the issue I am experiencing on the real project.

Thanks a lot!

1 Like

So, after days of trial end error I found a chromium flag that makes the gpu work on headless mode.

--use-cmd-decoder=passthrough

I don’t know why it works but it looks good and gives much faster results than swiftshader.

3 Likes