Print.js
Print.js copied to clipboard
"Print using system dialog..." silently fails to print
If I try to "Print using system dialog..." (tested on Chrome and Edge), the system dialog is opened but nothing happens.
When examining the Elements in the DevTools, the hidden iframe disappears as soon as the print preview closes, and is no longer available when the system dialog is displayed, which is probably whats causing the issue.
I've done some tests and can confirm that the issue started with commit 72d3b78 (Remove print iframe from DOM once job is complete) first made available in v1.5.0. We will revert to v1.4.0 for the time being.
The issue also seems to be related to #559 and #562.
The 'onfocus' event (for Chrome and Firefox) might be a good choice to trigger the onPrintDialogClose(), but may I suggest that removing the iframe from the DOM is triggered by another, unrelated (touch-friendly) event, since 'onfocus' is too soon.
I had good results when testing with 'mousedown', since the system print dialog is modal, as such:
const handler = () => {
// Make sure the event only happens once.
window.removeEventListener(event, handler)
params.onPrintDialogClose()
}
window.addEventListener(event, handler)
const handler2 = () => {
// Make sure the event only happens once.
window.removeEventListener(event, handler2)
// Remove iframe from the DOM
const iframe = document.getElementById(params.frameId)
if (iframe) {
iframe.remove()
}
}
window.addEventListener('mousedown', handler2)
Should this issue be fixed with the merge of #587 ? This issue only seems to be occurring on Angular, not AngularJS.
I experienced the same issue on Firefox and Chromium under Linux and Electron on Linux. In browsers the issue is very evident and happen almost 100% of times. With Electron the issue depends on the specific file. With PDF-A it is happening much more often (almost 100% of times), with other files it seems to happen rarely. In all cases the issue is solved by reverting to 1.4.0, so I expect the fix for this issue to be valid for Firefox, Chromium and Electron as well.