Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors when recording for longer than two minutes #88

Open
eliich opened this issue Apr 2, 2024 · 1 comment
Open

Errors when recording for longer than two minutes #88

eliich opened this issue Apr 2, 2024 · 1 comment

Comments

@eliich
Copy link

eliich commented Apr 2, 2024

  • I'm submitting a ...
    [x ] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

I have a current CLI tool, which takes a url. It will then slowly scroll while screen recording. The issue is that I have a scroll duration longer than 2 minutes I get a Error processing URLs: ProtocolError: Runtime.callFunctionOn timed out. Increase the 'protocolTimeout' setting in launch/connect calls for a higher timeout if needed. Error. Just wondering what could be the reason. Could possibly be an async issue? I am setting the time in my autoscroll function

  • Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

Entire Error Log

C:\Users\USER\Desktop\exampleSubreddit>auto-scroll-record https://www.reddit.com/r/exampleSubreddit
Processing URLs: [ 'https://www.reddit.com/r/exampleSubreddit' ]
Error processing URLs: ProtocolError: Runtime.callFunctionOn timed out. Increase the 'protocolTimeout' setting in launch/connect calls for a higher timeout if needed.
    at <instance_members_initializer> (C:\Users\USER\Programming\Projects\Node\auto-scroll-record\node_modules\puppeteer-core\lib\cjs\puppeteer\common\CallbackRegistry.js:93:14)
    at new Callback (C:\Users\USER\Programming\Projects\Node\auto-scroll-record\node_modules\puppeteer-core\lib\cjs\puppeteer\common\CallbackRegistry.js:97:16)
    at CallbackRegistry.create (C:\Users\USER\Programming\Projects\Node\auto-scroll-record\node_modules\puppeteer-core\lib\cjs\puppeteer\common\CallbackRegistry.js:22:26)
    at Connection._rawSend (C:\Users\USER\Programming\Projects\Node\auto-scroll-record\node_modules\puppeteer-core\lib\cjs\puppeteer\cdp\Connection.js:80:26)
    at CdpCDPSession.send (C:\Users\USER\Programming\Projects\Node\auto-scroll-record\node_modules\puppeteer-core\lib\cjs\puppeteer\cdp\CDPSession.js:66:33)
    at #evaluate (C:\Users\USER\Programming\Projects\Node\auto-scroll-record\node_modules\puppeteer-core\lib\cjs\puppeteer\cdp\ExecutionContext.js:202:50)
    at ExecutionContext.evaluate (C:\Users\USER\Programming\Projects\Node\auto-scroll-record\node_modules\puppeteer-core\lib\cjs\puppeteer\cdp\ExecutionContext.js:117:36)
    at IsolatedWorld.evaluate (C:\Users\USER\Programming\Projects\Node\auto-scroll-record\node_modules\puppeteer-core\lib\cjs\puppeteer\cdp\IsolatedWorld.js:124:30)
    at CdpFrame.evaluate (C:\Users\USER\Programming\Projects\Node\auto-scroll-record\node_modules\puppeteer-core\lib\cjs\puppeteer\api\Frame.js:343:43)
    at CdpFrame.<anonymous> (C:\Users\USER\Programming\Projects\Node\auto-scroll-record\node_modules\puppeteer-core\lib\cjs\puppeteer\util\decorators.js:98:27)

Entire script

const puppeteer = require('puppeteer');
const { PuppeteerScreenRecorder } = require('puppeteer-screen-recorder');
const fs = require('fs');
const path = require('path');

const Config = {
  followNewTab: true,
  fps: 60, // Increased to 60 for smoother motion
  ffmpeg_Path: null, // Default: let the library handle FFmpeg
  videoFrame: {
    width: 1920,
    height: 1080, // 16:9 aspect ratio at 1080p
  },
  videoCrf: 15, // Lowered for higher quality, where lower means better (default is 23-18)
  videoCodec: 'libx264',
  videoPreset: 'slow', // Using 'slow' for better compression efficiency at the cost of encoding speed
  videoBitrate: '8000k', // Increased bitrate for better quality
  autopad: false, // Disabled autopad
};

async function processUrls(urls) {
    console.log('Processing URLs:', urls);
    const browser = await puppeteer.launch({ 
        headless: false,
        timeout: 0, // Setting timeout to 0 disables the timeout
        defaultViewport: null, // Setting defaultViewport to null allows dynamic viewport
    });
    
    const videosDir = path.join(process.cwd(), 'videos');
    if (!fs.existsSync(videosDir)){
        fs.mkdirSync(videosDir, { recursive: true });
    }

    for (let url of urls) {
        const page = await browser.newPage();
        await page.setViewport({ width: 1920, height: 1080 }); // Ensure viewport matches recording resolution
        const recorder = new PuppeteerScreenRecorder(page, Config);
        
        const safeTitle = url.replace(/[^a-zA-Z]/g, "").slice(0, 10); // Keeping filenames short and safe
        const fileName = `${safeTitle}_${new Date().getTime()}.mp4`; // Unique filename for each recording
        const savePath = path.join(videosDir, fileName);
        
        await recorder.start(savePath);
        await page.goto(url, { waitUntil: 'networkidle2' });
        
        await autoScroll(page);
        
        await recorder.stop();
        await page.close();
    }

    await browser.close();
    console.log('Finished processing URLs.');
}

async function autoScroll(page) {
    await page.evaluate(() => {
        return new Promise((resolve) => {
            const totalTime = 180000; // 2 minutes in milliseconds
            const stepTime = 100; // time between steps in milliseconds

            // Define the smooth scroll function
            let lastTimestamp = performance.now();
            function smoothScroll() {
                const timestamp = performance.now();
                const progress = timestamp - lastTimestamp;

                // Calculate the distance to scroll based on the progress
                const distance = progress * 0.1; // Adjust speed here

                window.scrollBy(0, distance);
                lastTimestamp = timestamp;

                if (lastTimestamp - startTime < totalTime) {
                    requestAnimationFrame(smoothScroll);
                } else {
                    resolve();
                }
            }

            const startTime = performance.now();
            requestAnimationFrame(smoothScroll);
        });
    });
}

module.exports = { processUrls };
@LittleBearXD
Copy link

const browser = await puppeteer.launch({
headless:false,
...,
protocolTimeout: 1000 * 60 * 60
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants