Open Bug 1775392 Opened 2 years ago Updated 2 years ago

structuredClone throws DomException when called with ImageBitmap derived from OffscreenCanvas

Categories

(Core :: Graphics: Canvas2D, defect)

Firefox 101
defect

Tracking

()

UNCONFIRMED

People

(Reporter: william.archinal, Unassigned)

References

Details

Steps to reproduce:

  • Enable OffscreenCanvas (gfx.offscreencanvas.enabled = true)
  • Run this JS code:
const ctx = new OffscreenCanvas(width, height).getContext('2d');
await renderSomeContentOntoCanvas(ctx); // pseudocode, in our application this renders a JPEG onto the canvas
spritesheet = await createImageBitmap(ctx.canvas); // Returns ImageBitmap
structuredClone(spritesheet);

Actual results:

The final line throws:
DOMException: The object could not be cloned.

Expected results:

This should not have thrown an error.

Notably, if we use a HTMLCanvasElement instead of an OffscreenCanvas, the JS code works as expected.

The Bugbug bot thinks this bug should belong to the 'Core::Canvas: 2D' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Canvas: 2D
Product: Firefox → Core
Flags: needinfo?(aosmond)
Severity: -- → S3

I made a basic test case based on the example, but I think we need a bit more to go on. It can fail to clone for a bunch of reasons, mostly edge cases such as OOM, but the most likely are:

  1. The bitmap is marked as write only
  2. The bitmap is closed

It would be nice if we raised a better exception so that there is something more actionable for content authors.

I wrote a patch in bug 1777411 which should improve the error messages so that we can get a better idea of why the clone failed.

Blocks: 1777411

Can you retry on the latest nightly? The error message should be more useful for figuring out what happened.

Flags: needinfo?(aosmond) → needinfo?(william.archinal)

I'm still getting the same unspecific error message: "DataCloneError: The object could not be cloned."

This is on Firefox Nightly Version 104.0a1 (2022-07-03)

Flags: needinfo?(william.archinal)

Okay so it seems like it doesn't have anything to do with ImageBitmap then. We need a reduced test case to be actionable here.

You need to log in before you can comment on or make changes to this bug.