如何停止木偶录音机录音

how to stop puppeteer-recorder recording

我正在使用 puppeteer-recorder 从浏览器录制视频 activity

这个包裹 https://www.npmjs.com/package/puppeteer-recorder

这是我的代码

async function check_login()
{

    try {



        const page = await global_browser.newPage();
        await page.setViewport({width: 1000, height: 1100});

        record({
            browser: global_browser, // Optional: a puppeteer Browser instance,
            page: page, // Optional: a puppeteer Page instance,
            output: path + 'output.webm',
            fps: 60,
            frames: 60 * 5, // 5 seconds at 60 fps
            prepare: function () {}, // <-- add this line
            render: function () {} // <-- add this line

        });

        await page.goto('http://localhost/home_robot/mock.php', {timeout: 60000})
            .catch(function (error) {
                throw new Error('TimeoutBrows');
            });


        await page.close();



    }
    catch (e) {
        console.log(' LOGIN ERROR ---------------------');
        console.log(e);
    }
}

它工作正常,但我不知道如何停止录制,所以当我到达函数末尾时,我得到这个错误

(node:10000) UnhandledPromiseRejectionWarning: Error: Protocol error (Emulation.setDefaultBackgroundColorOverride): Target closed.
    at Promise (C:\wamp64\www\home_robot\node_modules\puppeteer\lib\Connection.js:202:56)
    at new Promise (<anonymous>)
    at CDPSession.send (C:\wamp64\www\home_robot\node_modules\puppeteer\lib\Connection.js:201:12)
    at Page._screenshotTask (C:\wamp64\www\home_robot\node_modules\puppeteer\lib\Page.js:806:26)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:10000) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (
rejection id: 1)
(node:10000) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我没有得到视频文件,我认为是因为我关闭了页面而没有停止记录

遗憾的是没有文档,作者也没有回答问题

没有办法也不需要用这个模块停止录制,仔细看record方法的frames选项:

frames: 60 * 5, // 5 seconds at 60 fps

300帧后自动停止。

然而,要让它工作,必须满足一个非常重要的要求,文档不会提及它,但您可以在模块的源代码中看到它:它使用 ffmpeg 从屏幕截图制作视频并且那必须在 PATH 中。如果不是,您应该在选项中提供 ffmpeg 二进制位置:

const puppeteer = require('puppeteer');
const { record } = require('puppeteer-recorder');

puppeteer.launch({headless : false}).then(async browser => {
    const page = await browser.newPage();

    await page.goto('https://codepen.io/hexagoncircle/full/joqYEj', {waitUntil : 'networkidle2'});

    await record({
        ffmpeg: "c:\ffmpeg\bin\ffmpeg.exe" // <-- provide full path to ffmpeg binary
        browser: browser, // Optional: a puppeteer Browser instance,
        page: page, // Optional: a puppeteer Page instance,
        output: 'output.webm',
        fps: 24,
        frames: 24, // desired seconds of recording multiplied by fps
        prepare: function (browser, page) { /* you could click on a button */ },
        render: function (browser, page, frame) { /* executed before each capture */ }
    });    

    await browser.close();
});

结果: