From 76d29759c5fc023a93281064914f3f642275b6c7 Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Wed, 17 Aug 2016 05:52:27 -0700 Subject: [PATCH] Avoid window.print in a microtask --- web/mozPrintCallback_polyfill.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/web/mozPrintCallback_polyfill.js b/web/mozPrintCallback_polyfill.js index afc4407a4..e8fde3c71 100644 --- a/web/mozPrintCallback_polyfill.js +++ b/web/mozPrintCallback_polyfill.js @@ -76,8 +76,16 @@ } } else { renderProgress(); - print.call(window); - setTimeout(abort, 20); // Tidy-up + // Push window.print in the macrotask queue to avoid being affected by + // the deprecation of running print() code in a microtask, see + // https://github.com/mozilla/pdf.js/issues/7547. + setTimeout(function() { + if (!canvases) { + return; // Print task cancelled by user. + } + print.call(window); + setTimeout(abort, 20); // Tidy-up + }, 0); } }