Hirad Nikoo
Hirad Nikoo

Reputation: 1629

Google Chrome Headless Error "Not supported" When using getDisplayMedia trying to record screen from Chrome Tab in Puppeteer

I am using Puppeteer latest version with Chromium 80 and I'm trying to record video from page in chrome headless and turned on all these flags:

{
  headless: true,
  devtools: false,
  args: [
    '--no-sandbox',
    '--allow-insecure-localhost',
    '--enable-usermedia-screen-capturing',
    '--use-fake-ui-for-media-stream', // In headless: false it will capture display rather than tab and in headless: true doesn't work
    '--auto-select-desktop-capture-source=[RECORD]', //[RECORD] is the title of my localhost page trying to screen capture
    '--remote-debugging-port=9222',
    '--window-size=1440,900',
  ],
  ignoreDefaultArgs: [
    '--mute-audio',
    '--disable-media-session-api',
  ]
}

On windows if this is headless : false it will capture the chrome tab (sometimes crashes). But if this is headless : true even on Windows it says it is Not supported. If --use-fake-ui-for-media-stream flag is on then it is another story and it will capture one of my displays regardless of being headless true or false.

Now I want to use this on my linux server where there is no display and I just want the chrome headless : true to capture my chrome tab. I know it can do that because I can see the screen in headless : true mode in the DevTools. If it is creating a display on DevTools it MUST be able to create the display on screen capture. I suppose there must be other flags to be turned on on Puppeteer so it is allowed to do so. I am using navigator.mediaDevices.getDisplayMedia in order to get the screen data.

I also have tried this video configuration and it didn't work (crashed) and apparently only works on extensions and I need to get source id from background:

screenStream = await navigator.mediaDevices.getDisplayMedia({
        video: {
            //mandatory: {
            //    chromeMediaSource: 'tab', // Not using this!
            //}
        },
        audio: false
});

Is there anyone that knows what flags should be also considered into the Puppeteer?

Please Note that I don't want to use xvfb and Selenium (WebDrive) or any extensions in my chrome headless.

Upvotes: 10

Views: 3026

Answers (1)

iѕєρєня
iѕєρєня

Reputation: 544

This issue is reported as a bug Here and also people on GitHub are having same issue. it seems its a bug and it's not clear when they are going to fix it.

In the meantime you can use puppeteer-video-recorder plugin which apparently works in headless and headful mode.

Does it record videos in headless Chrome?

Yes it does.

But since it uses FFMPEG the creation of the video seems to be slow. anyways, I hope you can use it and it helps you.

Upvotes: 3

Related Questions