joseluisq / printd

Print HTML elements or pages in modern browsers.
MIT License
80 stars 5 forks source link

Second print Empty #25

Open pedrozasantaigo opened 3 months ago

pedrozasantaigo commented 3 months ago

First printd.print works, but the second time doesn't and after.

jonek commented 3 months ago

In Chrome every print attempt after the first one shows an empty page in the print dialog and logs this to the console:

[Violation] Avoid using document.write(). https://developers.google.com/web/updates/2016/08/removing-document-write
print @ printd.umd.min.js:1
print @ pen.js:55
n @ vue.min.js:6
t @ vue.min.js:6

The beforeprint and afterprint events, that where logged for the first attempt, are not logged to the console anymore for the failing print attempts.

pedrozasantaigo commented 3 months ago

i resolved it creating a new instance each print time.

jonek commented 3 months ago

@pedrozasantaigo Surprisingly, creating a new printd instance seems to be indeed a successful workaround. I applied that workaround as well.

My first guess was that the usage of document.write() (as used here: /src/index.ts#L110 ) was the actual problem. But I was not able to confirm that with a locally patched version of printd.

For reference:

joseluisq commented 3 months ago

Feel free to submit a patch if any.