Using FabricJs in the background of Electron


#1

Hello guys,

I am looking for a solution on Google and StackOverflow and no luck so far.

Has anyone used FabricJs to save images in the background without user input?

In my app I’m running FabricJs as just a script and not as a Node library (it requires canvas and cairo to work in Node and it doesn’t seem to work well with Electron).

What I want is to save all the canvas created in FabricJs to images, because I will use the images to create a video. This works like a slideshow.

Thanks in advance


#2

So I think I found a solution to installing FabricJs as a normal NodeJs script.

I rebuilt the Electron for Native Modules (don’t know if that is really required or not).

And if you instlal FabricJs by npm and get the following error:

Uncaught Exception:
TypeError: Cannot read property ‘devicePixelRatio’ of undefined
at Object. (/Applications/Node/elfire/node_modules/fabric/dist/fabric.js:76:40)

The solution can drive you crazy but it probably means it is the wrong code, you have to go to node_modules/fabric/dist/fabric.js and to the line 76 and change the code.

In the file it says:
fabric.window = fabric.document.parentWindow;

but you have to change it to

fabric.window = fabric.document.defaultView;

That’s what worked for me