Bug 1222690 - SDK Content Script should not be frozen during the page loading. r?krizsa
MozReview-Commit-ID: JVnJZsSA6nO
--- 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;