How do you use the jsdom canvas support?

1,427 views
Skip to first unread message

David Besen

unread,
Jan 30, 2014, 3:50:52 PM1/30/14
to js...@googlegroups.com

Hi folks,

I'm relatively new to Javascript, and I'm trying to use jsdom, node.js, and canvas together on a Linux server.

I installed jsdom 0.8.11, canvas 1.1.3, and Node 0.10.7.

Here's my test code:

var jsdom = require("jsdom");
jsdom.env('<canvas id="myCanvas" width="300" height="300"></canvas>', [], function(errors, window) {
    console.log(window.document.getElementById("myCanvas"));
});

With canvas installed, I can't get this to output anything except 'null'.  Interestingly, if I don't have canvas installed, then this code prints a bunch of stuff, including "  _nodeName: 'canvas',".

Any ideas what I'm doing wrong?

Thanks,
Dave

Giovanni Bassi

unread,
Apr 1, 2014, 5:32:32 PM4/1/14
to js...@googlegroups.com
I have noticed that when using node-canvas all attributes are stripped from the element. The result is a simple '<canvas style=""></canvas>'. I don't think you are doing anything wrong, I think this is an unfixed problem. I just found an issue opened on Github regarding this problem:

qiu...@thoughtworks.com

unread,
Apr 8, 2014, 8:39:43 PM4/8/14
to js...@googlegroups.com
Hi,

Simply tried your way to use `canvas`, but failed. But you could use 'document.getElementsByTagName('canvas')' temporarily instead. 
Reply all
Reply to author
Forward
0 new messages