I am using puppeteer to take screengrabs of content in an application I have built. The majority of my code is working but I have a couple of scenarios where the results are not as expected.
I can successfully instruct puppeteer to take a screen grab of an element with a defined css height
and width
using getBoundingClientRect()
on the element but in scenarios where there is not defined height/width.
I was wondering if it was technically possible to get the height
and width
of an element based on the height
and width
of the inner elements.
For example (or the most likely case I am going to come across) I may have a piece of content where the body has no style parameters set but the inner content will have a height set. It might not be the first child element but it could even a child of the child element.
I have explored using get getBoundingClientRect()
and offsetHeight
but have had no success.
Is there a method that would allow me to get the calculated height / width of an element?
var body = document.querySelector('body');
console.log(body.clientHeight);
console.log(body.style.height);
console.log(body.getClientRects());
console.log(body.getBoundingClientRect());
#container {
height:200px;
width:200px;
background-color:blue;
border:1px solid black;
color: white;
text-align: center;
}
<body>
<div id="container">
HELLO
</div>
</body>