Bug 1332936 - hiding box model before taking the node's screenshot from inspector; r=pbro
authorMatteo Ferretti <mferretti@mozilla.com>
Wed, 15 Mar 2017 12:01:02 +0100
changeset 500836 ed2a004bb475c6227081650e7be0bd017a21a1bb
parent 500835 23cfb067130f6225f9b63c752c349fd607e69c46
child 500837 fd3bfde70bcfd9592e1c340422c7070180554068
push id49816
push userbmo:tchiovoloni@mozilla.com
push dateFri, 17 Mar 2017 20:44:02 +0000
reviewerspbro
bugs1332936
milestone55.0a1
Bug 1332936 - hiding box model before taking the node's screenshot from inspector; r=pbro MozReview-Commit-ID: 7MuC4KMLgJc
devtools/client/inspector/inspector.js
--- a/devtools/client/inspector/inspector.js
+++ b/devtools/client/inspector/inspector.js
@@ -1139,17 +1139,17 @@ Inspector.prototype = {
       hidden: !this._supportsScrollIntoView,
       disabled: !isSelectionElement,
       click: () => this.scrollNodeIntoView(),
     }));
     menu.append(new MenuItem({
       id: "node-menu-screenshotnode",
       label: INSPECTOR_L10N.getStr("inspectorScreenshotNode.label"),
       disabled: !isScreenshotable,
-      click: () => this.screenshotNode(),
+      click: () => this.screenshotNode().catch(console.error),
     }));
     menu.append(new MenuItem({
       id: "node-menu-useinconsole",
       label: INSPECTOR_L10N.getStr("inspectorUseInConsole.label"),
       click: () => this.useInConsole(),
     }));
     menu.append(new MenuItem({
       id: "node-menu-showdomproperties",
@@ -1762,26 +1762,33 @@ Inspector.prototype = {
     this.selection.nodeFront.getCssPath().then(path => {
       clipboardHelper.copyString(path);
     }).catch(e => console.error);
   },
 
   /**
    * Initiate gcli screenshot command on selected node.
    */
-  screenshotNode: function () {
+  screenshotNode: Task.async(function* () {
     const command = Services.prefs.getBoolPref("devtools.screenshot.clipboard.enabled") ?
       "screenshot --file --clipboard --selector" :
       "screenshot --file --selector";
+
+    // Bug 1332936 - it's possible to call `screenshotNode` while the BoxModel highlighter
+    // is still visible, therefore showing it in the picture.
+    // To avoid that, we have to hide it before taking the screenshot. The `hideBoxModel`
+    // will do that, calling `hide` for the highlighter only if previously shown.
+    yield this.highlighter.hideBoxModel();
+
     // Bug 1180314 -  CssSelector might contain white space so need to make sure it is
     // passed to screenshot as a single parameter.  More work *might* be needed if
     // CssSelector could contain escaped single- or double-quotes, backslashes, etc.
     CommandUtils.executeOnTarget(this._target,
       `${command} '${this.selectionCssSelector}'`);
-  },
+  }),
 
   /**
    * Scroll the node into view.
    */
   scrollNodeIntoView: function () {
     if (!this.selection.isNode()) {
       return;
     }