Bug 983386 - Prevent initializing canvas highlighter on loading or destroyed documents. r=pbro
MozReview-Commit-ID: 3Pa3r3HTyE7
--- a/devtools/server/actors/highlighters.js
+++ b/devtools/server/actors/highlighters.js
@@ -191,17 +191,19 @@ var HighlighterActor = exports.Highlight
this._highlighter.hide();
}
},
/**
* Hide the box model highlighting if it was shown before
*/
hideBoxModel: function () {
- this._highlighter.hide();
+ if (this._highlighter) {
+ this._highlighter.hide();
+ }
},
/**
* Returns `true` if the event was dispatched from a window included in
* the current highlighter environment; or if the highlighter environment has
* chrome privileges
*
* The method is specifically useful on B2G, where we do not want that events
--- a/devtools/server/actors/highlighters/utils/markup.js
+++ b/devtools/server/actors/highlighters/utils/markup.js
@@ -237,17 +237,22 @@ exports.createNode = createNode;
function CanvasFrameAnonymousContentHelper(highlighterEnv, nodeBuilder) {
this.highlighterEnv = highlighterEnv;
this.nodeBuilder = nodeBuilder;
this.anonymousContentDocument = this.highlighterEnv.document;
// XXX the next line is a wallpaper for bug 1123362.
this.anonymousContentGlobal = Cu.getGlobalForObject(
this.anonymousContentDocument);
- this._insert();
+ // Only try to create the highlighter when the document is loaded,
+ // otherwise, wait for the navigate event to fire.
+ let doc = this.highlighterEnv.document;
+ if (doc.documentElement && doc.readyState != "uninitialized") {
+ this._insert();
+ }
this._onNavigate = this._onNavigate.bind(this);
this.highlighterEnv.on("navigate", this._onNavigate);
this.listeners = new Map();
}
CanvasFrameAnonymousContentHelper.prototype = {