How to await all chrome-PDF layout work before measuring elements?
-
I need to measure some elements. This works great with the following concept:
- In a script tag, iterate alle elements and collect element.getBoundingClientRect()
- stringify the measures and mashal them to the server side via console.log
- add measurement data to req.data
- start a second render where I now have access to the measurements
Unfortunately, I'm having trouble with the timing. I'm currently measuring at
window.onload
. It seems as chrome-pdf applies the automatic page breaks after my measurements. I.e. the boundingboxes will sometimes relate to the position the element had before chrome-pdf added the automatic pagebreaks.Is there any way to await the complete layout?
I tried with a simple setTimeout but jsReport does not await such timeouts on the client side.
I also tried to setwindow.JSREPORT_READY_TO_START = false;
and then set it to true after my timeout, but jsReport did not wait for this.
-
Update:
I got window.JSREPORT_READY_TO_START to work by ckecking "wait for printing trigger", but the measurement are still taken before automatic page breaks.I have tried both setTimeout and requestAnimationFrame. Is there no way to await chrome-pdf's automatic page breaking before taking measurements?