How to get element/page width

I found that using the element’s clientWidth to get its actual width will return 0 when the element is not on the screen or not rendered.

Is there a stable method to get the element width or the page width?