Home > other >  Why chromium doesn't open in headless Mode?
Why chromium doesn't open in headless Mode?

Time:11-05

I have the following NodeJS code to open Chromium in headless mode and record a web page to a video :

    const { launch, getStream }  = require("puppeteer-stream");
    const fs = require("fs");
    const { exec } = require("child_process");

    async function test() {         
        const browser = await launch({headless: true});

        const page = await browser.newPage();
        await page.goto("https://www.someurl.com");
        const stream = await getStream(page, { audio: true, video: true});
        
        // record the web page to mp4 video
        const ffmpeg = exec('ffmpeg -y -i - output.mp4');

        stream.pipe(ffmpeg.stdin);

        setTimeout(async () => {
            await stream.destroy();
            stream.on("end", () => {});
        }, 1000 * 60);
    }

The following code works properly but doesn't open chromium in headless mode. No matter what I do, the browser is still opened and visible when browsing the page. No error is thrown.

Does anyone know why it's not opened in headless mode please ?

Thanks

CodePudding user response:

It says in the documentation for puppeteer-stream:

Notice: This will only work in headful mode

This is due to a limitation of Chromium where the Tab Capture API for the extension doesn't work in headless mode. (There are a couple bug reports about this, but I can't find the links at the moment.)

  • Related