Bug 1222690 - SDK Content Script should not be frozen during the page loading. r?krizsa draft
authorLuca Greco <lgreco@mozilla.com>
Mon, 20 Jun 2016 16:33:21 +0200
changeset 380052 710c53362b5972434a13ca2969159a69c0d666b2
parent 379985 3c5025f98e561a20e24d97c91a9e4e0ec28015ea
child 380053 556ed588b07da256163763f0dc8ccd3d77c34ced
push id21119
push userluca.greco@alcacoop.it
push dateMon, 20 Jun 2016 14:36:28 +0000
reviewerskrizsa
bugs1222690
milestone50.0a1
Bug 1222690 - SDK Content Script should not be frozen during the page loading. r?krizsa MozReview-Commit-ID: JVnJZsSA6nO
addon-sdk/source/lib/sdk/content/worker-child.js
--- a/addon-sdk/source/lib/sdk/content/worker-child.js
+++ b/addon-sdk/source/lib/sdk/content/worker-child.js
@@ -46,19 +46,29 @@ const WorkerChild = Class({
     for (let topic in EVENTS)
       system.on(topic, this.observe);
 
     this.receive = this.receive.bind(this);
     process.port.on('sdk/worker/message', this.receive);
 
     this.sandbox = WorkerSandbox(this, this.window);
 
-    // If the document is still loading wait for it to finish before passing on
-    // received messages
-    this.frozen = this.window.document.readyState == "loading";
+    // If the document has an unexpected readyState, its worker-child instance is initialized
+    // as frozen until one of the known readyState is reached.
+    let initialDocumentReadyState = this.window.document.readyState;
+    this.frozen = [
+      "loading", "interactive", "complete"
+    ].includes(initialDocumentReadyState) ? false : true;
+
+    if (this.frozen) {
+      console.warn("SDK worker-child started as frozen on unexpected initial document.readyState", {
+        initialDocumentReadyState, windowLocation: this.window.location.href,
+      });
+    }
+
     this.frozenMessages = [];
     this.on('pageshow', () => {
       this.frozen = false;
       this.frozenMessages.forEach(args => this.sandbox.emit(...args));
       this.frozenMessages = [];
     });
     this.on('pagehide', () => {
       this.frozen = true;