Closed
Bug 1492357
Opened 8 years ago
Closed 1 month ago
"WebDriver:TakeScreenshot" doens't throw "unable to capture screen" error if height or width of captured image is 0
Categories
(Remote Protocol :: Marionette, defect, P3)
Tracking
(firefox158 fixed)
RESOLVED
FIXED
158 Branch
| Tracking | Status | |
|---|---|---|
| firefox158 | --- | fixed |
People
(Reporter: mozilla, Assigned: f3tchcodes)
References
(Blocks 2 open bugs)
Details
(Whiteboard: [webdriver:m21][webdriver:external][wptsync upstream][webdriver:relnote])
Attachments
(2 external files)
User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36
Steps to reproduce:
Launch geckodriver:
```bash
./geckodriver --port=7000
```
Start a web server:
```bash
python3 -m http.server 9080
```
Create an empty test page empty.html with 0 margin and a background color:
```
<html><head><title></title></head><body style="background: #1289af; margin:0px;"></body></html>
```
Run the following script:
```bash
#!/bin/bash
SESSIONID=$(curl -X POST -d '{"capabilities":{"alwaysMatch":{"moz:firefoxOptions":{"args":["--headless"]}}}}' http://localhost:7000/session | jq -r ".value.sessionId")
echo "SESSIONID: ${SESSIONID}"
curl -v -X POST -d '{"url": "http://localhost:9080/empty.html"}' http://localhost:7000/session/${SESSIONID}/url
json=$(curl -v http://localhost:7000/session/${SESSIONID}/screenshot)
echo "${json}"
echo "${json}" | jq -r ".value" | base64 -d > empty.png
```
Actual results:
The resulting image file empty.png is not a valid PNG file (0 bytes). Specifically the base64 string returned by the screenshot command is empty.
Expected results:
The returned screenshot should be a valid PNG file. I suspect what is happening is that because the screenshot misbehavior of taking a screenshot of the body content rather than the viewport (https://bugzilla.mozilla.org/show_bug.cgi?id=1385706), the screenshot code is short-circuiting when it sees 0x0 data and returns nothing instead of a valid 0x0 PNG file.
Comment 1•8 years ago
|
||
I can see this too with the recent Nightly build of Firefox. When quickly debugging it the problem seems to be located here:
> canvas.toDataURL("image/png");
This only returns "data:," without any MIME type, and no data.
A check on MDN shows the following:
https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL
> If the height or width of the canvas is 0, the string "data:," is returned.
I had a look at the WebDriver specification and it says the following:
https://w3c.github.io/webdriver/#dfn-encoding-as-base64
> If the canvas element’s bitmap has no pixels (i.e. either its horizontal dimension or vertical dimension is zero) then return error with error code unable to capture screen.
It means we miss to throw this defined error.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3
Summary: Screenshot of page with only background image results in invalid image file (0 bytes) → "WebDriver:TakeScreenshot" doens't throw "unable to capture screen" error if height or width of captured image is 0
Updated•4 years ago
|
Severity: normal → S3
Updated•3 years ago
|
Product: Testing → Remote Protocol
| Assignee | ||
Comment 3•1 month ago
|
||
Updated•1 month ago
|
Assignee: nobody → f3tch.169
Status: NEW → ASSIGNED
| Assignee | ||
Comment 4•1 month ago
|
||
Updated•1 month ago
|
Attachment #9646666 -
Attachment description: Bug 1492357 - Add tests for zero-size screenshots. r?whimboo → Bug 1492357 - [wdspec] Add tests for zero-size screenshots. r?whimboo
Pushed by hskupin@mozilla.com:
https://github.com/mozilla-firefox/firefox/commit/1b34be62e38b
https://hg.mozilla.org/integration/autoland/rev/c8fdc2d18761
'WebDriver:TakeScreenshot' doens't throw 'unable to capture screen' error if height or width of captured image is 0. r=whimboo,geckodriver-reviewers,webdriver-reviewers
https://github.com/mozilla-firefox/firefox/commit/e364f93541d8
https://hg.mozilla.org/integration/autoland/rev/42e2a0123ee6
[wdspec] Add tests for zero-size screenshots. r=whimboo,webdriver-reviewers
Comment 6•1 month ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/c8fdc2d18761
https://hg.mozilla.org/mozilla-central/rev/42e2a0123ee6
Status: ASSIGNED → RESOLVED
Closed: 1 month ago
status-firefox158:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → 158 Branch
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/62890 for changes under testing/web-platform/tests
Updated•1 month ago
|
Whiteboard: [webdriver:m21][webdriver:external]
Upstream PR merged by moz-wptsync-bot
Whiteboard: [webdriver:m21][webdriver:external] → [webdriver:m21][webdriver:external], [wptsync upstream]
Updated•1 month ago
|
Whiteboard: [webdriver:m21][webdriver:external], [wptsync upstream] → [webdriver:m21][webdriver:external][wptsync upstream][webdriver:relnote]
You need to log in
before you can comment on or make changes to this bug.
Description
•