Forum How do I...?

When does Prince decide to process the DOM?

kevinwjames
Glad to see more JS support added, including setTimeout. One thing I'm confused about though, is how does Prince decide when to stop JS execution and process the page?

In other words, if I'm running some async code which may continue after onload, is there a way to tell Prince to wait? Or does it keep track of setTimeout/setInterval and wait for them all to finish?
mikeday
Timeouts will run immediately, they will not actually wait, and conversion will start when they are finished.
natevw
If timeouts are immediately processed, why would some scripts cause a "warning: pending timeouts" message? What does it mean?

I've seen some other posts that imply perhaps you can't call setTimeout from another setTimeout handler. Is that still the case, or has this restriction been removed by the time the current Prince 11.3 is released?
natevw
Also, can you clarify what you mean by "timeouts will run immediately"? In what order will the messages be output from code like this?

Log.message("sync message 0");
setTimeout(function () { Log.message("slow timeout") }, 1.5e3);
setTimeout(function () { Log.message("fast timeout") }, 0);
Log.message("sync message 1")
mikeday
Support for setTimeout was improved in Prince 11.2, now it will run 10 seconds worth of timeouts in the correct order but without actually waiting for 10 seconds.

So your example will print this:
prince: warning: sync message 0
prince: warning: sync message 1
prince: warning: fast timeout
prince: warning: slow timeout

(I changed Log.message to Log.warning as we don't support Log.message).