From 930a28d879af0e42f2cabe98c2c74514c900da0f Mon Sep 17 00:00:00 2001
From: Yury Delendik <ydelendik@mozilla.com>
Date: Tue, 10 Jan 2017 08:49:08 -0600
Subject: [PATCH] Better DOMContentLoaded handling.

---
 web/viewer.js | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/web/viewer.js b/web/viewer.js
index a743e7e08..01c27a608 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -169,15 +169,9 @@ function webViewerLoad() {
   var config = getViewerConfiguration();
   if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
     require.config({paths: {'pdfjs': '../src', 'pdfjs-web': '.'}});
-    require(['pdfjs-web/pdfjs'], function () {
-      // Ensure that src/main_loader.js has loaded all the necessary
-      // dependencies *before* the viewer loads, to prevent issues in browsers
-      // relying on e.g. the Promise/URL polyfill in src/shared/util.js (fixes
-      // issue 7448).
-      require(['pdfjs-web/app', 'pdfjs-web/pdf_print_service'], function (web) {
-        window.PDFViewerApplication = web.PDFViewerApplication;
-        web.PDFViewerApplication.run(config);
-      });
+    require(['pdfjs-web/app', 'pdfjs-web/pdf_print_service'], function (web) {
+      window.PDFViewerApplication = web.PDFViewerApplication;
+      web.PDFViewerApplication.run(config);
     });
   } else {
     window.PDFViewerApplication = pdfjsWebLibs.pdfjsWebApp.PDFViewerApplication;
@@ -185,4 +179,9 @@ function webViewerLoad() {
   }
 }
 
-document.addEventListener('DOMContentLoaded', webViewerLoad, true);
+if (document.readyState === 'interactive' ||
+    document.readyState === 'complete') {
+  webViewerLoad();
+} else {
+  document.addEventListener('DOMContentLoaded', webViewerLoad, true);
+}