explainers icon indicating copy to clipboard operation
explainers copied to clipboard

preparePrint() followed by print() may not do what is intended

Open schenney-chromium opened this issue 4 months ago • 0 comments

It's plausible that after preparePrint() has been called and executed, the browser may perform layout again before script has a chance to call print(). The browser may then decide that the loaded resources are not needed and release them. This creates a race condition on calling print() before resources are released. Regardless of resources, it will create style and layout churn.

Firefox would not have this problem because it snapshots the document before printing. But Chrome and Safari probably both have this potential problem.

The solution is to roll prepare and print together as, for example, requestPrint() which is essentially an async print().

Another option is to return some handle that will keep the print-ready document alive, though it would be challenging for Chromium and Safari, I think.

schenney-chromium avatar Sep 09 '25 22:09 schenney-chromium