I stepped on that beartrap just last week, Chrome at least will swallow the rest of the page looking for the missing </script>.
Context: bulk export of thousands of legacy CGI HTML pages using "chrome --headless" to archive to PDF. The cause was a side effect of xmlstarlet which I used to inject links for CSS and JS rendering fix ups for PDF. The result was perfectly rendered 1-page blank PDFs :/