Bug 1249119 - Prevent trying to initialize highlighter on still-loading documents. r=pbro
MozReview-Commit-ID: 3S0LoB40q2W
--- a/devtools/server/actors/highlighters.js
+++ b/devtools/server/actors/highlighters.js
@@ -92,17 +92,22 @@ var HighlighterActor = exports.Highlight
this._tabActor = this._inspector.tabActor;
this._highlighterEnv = new HighlighterEnvironment();
this._highlighterEnv.initFromTabActor(this._tabActor);
this._highlighterReady = this._highlighterReady.bind(this);
this._highlighterHidden = this._highlighterHidden.bind(this);
this._onNavigate = this._onNavigate.bind(this);
- this._createHighlighter();
+ let doc = this._tabActor.window.document;
+ // Only try to create the highlighter when the document is loaded,
+ // otherwise, wait for the navigate event to fire.
+ if (doc.documentElement && doc.readyState != "uninitialized") {
+ this._createHighlighter();
+ }
// Listen to navigation events to switch from the BoxModelHighlighter to the
// SimpleOutlineHighlighter, and back, if the top level window changes.
events.on(this._tabActor, "navigate", this._onNavigate);
},
get conn() {
return this._inspector && this._inspector.conn;
--- a/devtools/server/actors/highlighters/utils/markup.js
+++ b/devtools/server/actors/highlighters/utils/markup.js
@@ -263,23 +263,26 @@ CanvasFrameAnonymousContentHelper.protot
this.highlighterEnv = this.nodeBuilder = this._content = null;
this.anonymousContentDocument = null;
this.anonymousContentGlobal = null;
this._removeAllListeners();
},
_insert: function () {
- // Insert the content node only if the page isn't in a XUL window, and if
- // the document still exists.
- if (!this.highlighterEnv.document.documentElement ||
+ let doc = this.highlighterEnv.document;
+ // Insert the content node only if the document:
+ // * is loaded (navigate event will fire once it is),
+ // * still exists,
+ // * isn't in XUL.
+ if (doc.readyState == "uninitialized" ||
+ !doc.documentElement ||
isXUL(this.highlighterEnv.window)) {
return;
}
- let doc = this.highlighterEnv.document;
// For now highlighters.css is injected in content as a ua sheet because
// <style scoped> doesn't work inside anonymous content (see bug 1086532).
// If it did, highlighters.css would be injected as an anonymous content
// node using CanvasFrameAnonymousContentHelper instead.
installHelperSheet(this.highlighterEnv.window,
"@import url('" + STYLESHEET_URI + "');");
let node = this.nodeBuilder();