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

ReferenceError: window is not defined #140

Open
HongYangWitness opened this issue May 27, 2022 · 2 comments
Open

ReferenceError: window is not defined #140

HongYangWitness opened this issue May 27, 2022 · 2 comments

Comments

@HongYangWitness
Copy link

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
Copy link

GoToLoop commented May 27, 2022

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
Copy link
Author

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!

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