takeScreenshot() for non-browser chrome windows fail because getBoundingClientRect() returns width=0 and height=0

RESOLVED WORKSFORME

Status

defect
RESOLVED WORKSFORME
4 years ago
3 years ago

People

(Reporter: whimboo, Unassigned)

Tracking

(Blocks 1 bug)

45 Branch
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

https://treeherder.mozilla.org/logviewer.html#?job_id=3270254&repo=mozilla-central#L1233

Taking the screenshot failed due to the following error:

 10:17:13     INFO -  Marionette threw an error: [Exception... "Failure"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  location: "JS frame :: chrome://marionette/content/driver.js :: GeckoDriver.prototype.takeScreenshot :: line 2629"  data: no]
 10:17:13     INFO -  GeckoDriver.prototype.takeScreenshot@chrome://marionette/content/driver.js:2629:7
 10:17:13     INFO -  Dispatcher.prototype.execute/req<@chrome://marionette/content/dispatcher.js:126:20
 10:17:13     INFO -  TaskImpl_run@resource://gre/modules/Task.jsm:319:40
 10:17:13     INFO -  TaskImpl@resource://gre/modules/Task.jsm:280:3
 10:17:13     INFO -  createAsyncFunction/asyncFunction@resource://gre/modules/Task.jsm:254:14
 10:17:13     INFO -  Task_spawn@resource://gre/modules/Task.jsm:168:12
 10:17:13     INFO -  Dispatcher.prototype.execute@chrome://marionette/content/dispatcher.js:120:13
 10:17:13     INFO -  Dispatcher.prototype.onPacket@chrome://marionette/content/dispatcher.js:91:5
 10:17:13     INFO -  DebuggerTransport.prototype._onJSONObjectReady/<@chrome://marionette/content/server.js -> resource://devtools/shared/transport/transport.js:479:9
 10:17:13     INFO -  exports.makeInfallible/<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/shared/ThreadSafeDevToolsUtils.js:101:14
 10:17:13     INFO -  exports.makeInfallible/<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/shared/ThreadSafeDevToolsUtils.js:101:14
 10:17:13  WARNING - Failed to gather test failure debug.

This is the appropriate code:

https://dxr.mozilla.org/mozilla-central/source/testing/marionette/driver.js#2629

      context.scale(scale, scale);
  >   context.drawWindow(win, 0, 0, width, height, "rgb(255,255,255)", flags);
      let dataUrl = canvas.toDataURL("image/png", "");

Not sure yet if that had an influence for our test because it was also failing. So adding dependency for now to bug 1247596.
I checked this again and actually this is a bug of the screenshot method when a non-browser chrome window is the active chrome window.

After testing all variables to the drawWindow() call I noticed that both width and height are 0. They are retrieved via getBoundingClientRect() based on win.document.documentElement.

So it looks like that we need another method to determine the width and height of the chrome window.
Summary: Marionette threw an error: [Exception... "Failure" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: chrome://marionette/content/driver.js :: GeckoDriver.prototype.takeScreenshot :: line 2629" data: no] 10:17:13 INFO - GeckoDriver. → takeScreenshot() for non-browser chrome windows fail because getBoundingClientRect() returns width=0 and height=0
When I use the DOMInspector for the about window I can see that the documentElement has a clientWidth and clientHeight property. Both have plausible values but when I dump those in takeScreenshot() I see 0. So not sure what's going on here.
I tried to reproduce this failure but I'm not able to. I will close this bug for now. Lets reopen if it happens again.
Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.