ccapture.js icon indicating copy to clipboard operation
ccapture.js copied to clipboard

ReferenceError: window is not defined

Open HongYangWitness opened this issue 2 years ago • 2 comments

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

HongYangWitness avatar May 27 '22 21:05 HongYangWitness

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

GoToLoop avatar May 27 '22 21:05 GoToLoop

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!

HongYangWitness avatar May 27 '22 21:05 HongYangWitness