spite / ccapture.js

A library to capture canvas-based animations at a fixed framerate
MIT License
3.59k stars 407 forks source link

ReferenceError: window is not defined #140

Open HongYangWitness opened 2 years ago

HongYangWitness commented 2 years ago

I am trying to use capture to record the fabric.js canvas. I download files via git and import them.

image

When I tried to use ccapture, it shows me the error as follows. What should I do? CCapture.js:55

image
GoToLoop commented 2 years ago

Property window by default doesn't exist in a Node.js server but only in a browser client environment: https://developer.Mozilla.org/en-US/docs/Web/API/Window/window

For client/server compatibility window needs to be replaced by globalThis: https://developer.Mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis

Even doing so, ccapture.js is a client library to capture a browser canvas element, which don't exist in a server environment by default.

Also, ccapture.js is distributed as a vanilla JS script file named "CCapture.all.min.js". We can't use keyword import on a browser context b/c "CCapture.all.min.js" isn't a module script file: https://developer.Mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules

HongYangWitness commented 2 years ago

I see. So this means it doesn't work with fabric.js canvas that using the node-canvas when it runs on node.js server, right? Thank you!