Bug 1222690 - SDK Content Script should not be frozen during the page loading. r=gabor a=sylvestre
authorLuca Greco <lgreco@mozilla.com>
Mon, 20 Jun 2016 16:33:21 +0200
changeset 341704 9be81aef870adb32b644dfdf5fd4105f3202b5a8
parent 341703 f74a3bf1496e1918fa29d0ef906b2efcc17fe852
child 341705 d09ce0726c25a837b4fa2db62bb8dce0554c8374
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor, sylvestre
bugs1222690
milestone49.0a2
Bug 1222690 - SDK Content Script should not be frozen during the page loading. r=gabor a=sylvestre 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;