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

Error: Uncaught [TypeError: window.CCapture is not a constructor] #137

Open
Tribevote opened this issue Jan 4, 2022 · 1 comment
Open

Comments

@Tribevote
Copy link

I'm trying to load CCapture in Node.js, I keep getting window.CCapture is not a constructor error.

Here is my code

const jsdom = require("jsdom");
const { JSDOM } = jsdom;

const { window } = new JSDOM(`<!DOCTYPE html><body>
<script src='./node_modules/ccapture.js/build/CCapture.all.min.js'></script>
<canvas id="canvas" width="200" height="100"></canvas>
</body>`,
// We need these options to allow JSDOM to require CCapture from node_modules
{ runScripts: "dangerously", resources: "usable" });
  
const document = window.document;

window.onload = () => {
        console.log("Onload >>>>>>");
        const canvas = document.getElementById("canvas");
        const canvas = createCanvas(200, 200)

        const ctx = canvas.getContext("2d");
        var colors = ["red", "blue", "yellow", "orange", "black", "white", "green"];

        function draw (){

            ctx.fillStyle = colors[Math.floor(Math.random() * colors.length)];
            ctx.fillRect(0, 0, canvas.width, canvas.height);
        }
        draw();

        
        var capturer = new window.CCapture( {
            format: 'ffmpegserver',
            framerate: 60,
            verbose: true,
            name: "foobar",     // videos will be named foobar-#.mp4, untitled if not set.
            extension: ".mp4",  // extension for file. default = ".mp4"
            codec: "mpeg4",     // this is an valid ffmpeg codec "mpeg4", "libx264", "flv1", etc...
                                // if not set ffmpeg guesses based on extension.
        } );

        console.log("Capture>>>>>", capturer);


   
  };

@umairafzal9245
Copy link

did you get a solution?

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