Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get DOM element's actual width using jsdom

Tags:

node.js

jsdom

I wonder if I could get a DOM element's actual width and coordinates, as I can get using .clientWidth / .offsetWidth from within the browser.

Does jsdom has browser rendering capabilities in order to get this data?

If not, how can I get this within node.js server?

Thanks!

like image 627
tomericco Avatar asked Nov 11 '13 19:11

tomericco


1 Answers

JSDOM is strictly a DOM API emulation library. It does not attempt to actually render a document, which is necessary to compute element size and position.

You may want to look at PhantomJS. It is a full WebKit renderer with a JavaScript API. It is entirely separate from node, so you either need to write a utility script using Phantom's API, or use a npm module that lets you control Phantom from node.

like image 112
josh3736 Avatar answered Sep 20 '22 17:09

josh3736