Closed Bug 1994148 Opened 6 months ago Closed 3 months ago

browsingContext.captureScreenshot should return an error instead of a screenshot with a reduced size

Categories

(Remote Protocol :: WebDriver BiDi, defect, P3)

defect

Tracking

(firefox149 fixed)

RESOLVED FIXED
149 Branch
Tracking Status
firefox149 --- fixed

People

(Reporter: hbenl, Assigned: sameembaba, Mentored)

References

(Blocks 1 open bug)

Details

(Whiteboard: [webdriver:m19][webdriver:external][lang=js], [wptsync upstream][webdriver:relnote])

Attachments

(1 file)

Currently, browsingContext.captureScreenshot caps the screenshot size if the requested size is too large. But the BiDi spec says that it should return an unsupported operation error if it can't capture a screenshot (which in my opinion includes this case where the browser can only capture a screenshot with a reduced size).

I think that we should better update step 13 of the remote end steps and use the trying mechanism. If render the document to a canvas fails we probably want to raise a unable to capture screen error as well.

It should indeed be step 3 because that's the place where the canvas is created. So unsupported operation error is correct.

Mentor: hskupin
Severity: -- → S3
Priority: -- → P3
Whiteboard: [webdriver:backlog][lang=js]

Hi, I’ve got my local setup ready! would it be okay if I work on this issue?

Sameem, you are welcome to work on this bug. Let me know in case you have questions. Thanks!

Thanks! I'm getting started now.

I've located the resize logic in remote/shared/Capture.sys.mjs inside capture.canvas. My plan is to remove the code that caps the dimensions and replace it with an error check.

Assignee: nobody → ssssameembaba
Status: NEW → ASSIGNED
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/57564 for changes under testing/web-platform/tests
Whiteboard: [webdriver:backlog][lang=js] → [webdriver:backlog][lang=js], [wptsync upstream]
Status: ASSIGNED → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → 149 Branch
Upstream PR merged by moz-wptsync-bot

Thank you so much Sameem!

Whiteboard: [webdriver:backlog][lang=js], [wptsync upstream] → [webdriver:m19][webdriver:external][lang=js], [wptsync upstream]

As I just saw, in Firefox we increased the maximum size for screenshots to 65535x65535 pixels to match Chrome's behavior. The changes landed end of January this year via bug 1911583. That's the reason why the most recent testing didn't throw an error with 32767x32767 sizes.

We just have to change the test dimension to fix it! When we landed the patch i don't think it had any problem with the test we wrote. So, what is the plan?

Hm, I wonder why the test def test_huge_full_screenshot in testing/web-platform/mozilla/tests/webdriver/classic/take_full_screenshot/screenshot.py still passes. I would expect that it fails now.

Sameem, I'm currently away until next week. So if you could file a new bug and take a look why the error is still thrown for the above test it would be great. My colleagues in the #webdriver channel can help you in case of questions. Thanks!

Yeah, they should all fail the new test i have created as they have the previous boundaries(32768px)! I will check what is wrong here

I did some test and i see when i instrumented capture.canvas. Canvas allocation succeeds with 32768×32768 (DPR=1). The failure occurs inside drawSnapshot, which throws NS_ERROR_LOSS_OF_SIGNIFICANT_DATA which we catch and throw an UnsupportedOperationError. That is why the the test still passes

Hey there, i got busy last week! So, I didnt have time to work on it! The above message i sent about the different error being is this how it supposed behavior or do we have to change it?

Interesting. First, could you check if it also fails with drawWindow() (the other code block)? Just force readback to be true for this purpose. Maybe they only increased it for that code path. If yes we would have to think about how to better handle it.

I tested both paths:

drawWindow() fails in the Canvas 2D layer with InvalidStateError: Canvas exceeds max size, due to the gfx.canvas.max-area limit.
drawSnapshot() fails deeper in the snapshot/compositor pipeline with NS_ERROR_LOSS_OF_SIGNIFICANT_DATA.

(In reply to Sameem [:sameembaba] from comment #19)

I tested both paths:

drawWindow() fails in the Canvas 2D layer with InvalidStateError: Canvas exceeds max size, due to the gfx.canvas.max-area limit.
drawSnapshot() fails deeper in the snapshot/compositor pipeline with NS_ERROR_LOSS_OF_SIGNIFICANT_DATA.

Hi Lee, given that you wrote the patch on bug 1911583 maybe you can help us? Maybe it was not intended to use larger canvas sizes for screenshots, especially when both the width and height larger than 32767? Or it is a miss and we should add proper support for it? Thanks!

Flags: needinfo?(lsalzman)

(In reply to Henrik Skupin [:whimboo][⌚️UTC+1] from comment #20)

(In reply to Sameem [:sameembaba] from comment #19)

I tested both paths:

drawWindow() fails in the Canvas 2D layer with InvalidStateError: Canvas exceeds max size, due to the gfx.canvas.max-area limit.
drawSnapshot() fails deeper in the snapshot/compositor pipeline with NS_ERROR_LOSS_OF_SIGNIFICANT_DATA.

Hi Lee, given that you wrote the patch on bug 1911583 maybe you can help us? Maybe it was not intended to use larger canvas sizes for screenshots, especially when both the width and height larger than 32767? Or it is a miss and we should add proper support for it? Thanks!

To be compatible with our Skia backends, the total size still needs to fit in a signed 32-bit integer to not overflow. For compat, we needed to be able to support sizes such as 64000x10, which is a very small area objectively, but has a dimension over the previous 32K limit. We, however, would not support a 64000x64000 canvas, because that would violate the constraint that the size can fit in signed 32 bits without overflow.

Essentially, I kept the area constraint to the same effective value as would be imposed by a 32K x 32K limit (as I am not sure yet we want to allow canvases that can consume more memory internally without any headroom), but I allow individual dimensions to reach up to 64K. The gfx.canvas.max-area pref implements this constraint.

Flags: needinfo?(lsalzman)

Thank you Lee!

Sameem, with the above information I may propose that we re-add a check that the size of the screenshot doesn't exceed the gfx.canvas.max-area value. That way we would be flexible with any future change and as well could raise a specific error beside any other platform error which could happen as well. Would you like to file and work on such a bug?

Flags: needinfo?(ssssameembaba)

Yeah! I would like to work on it

Flags: needinfo?(ssssameembaba)

Great. I filed bug 2020302 for it.

Whiteboard: [webdriver:m19][webdriver:external][lang=js], [wptsync upstream] → [webdriver:m19][webdriver:external][lang=js], [wptsync upstream][webdriver:relnote]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: