Open Kaiido opened 10 months ago
Setting width/height or attempting to read the bitmap of a detached OffscreenCanvas are programming errors IMHO. I am pretty sure throwing an InvalidState exception is the right thing to do in almost all cases.
For the placeholder
Setting width/height or attempting to read the bitmap of a detached OffscreenCanvas are programming errors IMHO. I am pretty sure throwing an InvalidState exception is the right thing to do in almost all cases.
Agreed, I'll take it as a Chrome position and will try to prepare a PR to that effect when I get time.
For the placeholder situation, could you clarify what the problematic use case is?
I was only talking about the relation OffscreenCanvas => placeholder<canvas>
. I simply noticed that the OffscreenCanvas
's placeholder canvas element isn't unset in the transfer steps and since the width
and height
setters aren't defined (yet) for when context mode is detached
what happens to the placeholder canvas is also unspecced.
But I now see that even the context mode: none
has some small interop issues with placeholder canvases, and the specs seem unclear here too. See this fiddle where we can see that Safari does resize the placeholder canvas even when there is no context on the OffscreenCanvas, while Firefox will wait until the context is created and Chrome until there is actual drawings on the context. All the specs say is that commit()
was supposed to be updating the placeholder size, which is going to be replaced by "update the rendering".
What is the issue with the HTML Standard?
OffscreenCanvas
can have a detached context mode, once theOffscreenCanvas
object has been transferred.The transferring steps say that
value
(theOffscreenCanvas
object)'s bitmap must be unset, but apart from that it doesn't say much of what else happens to said object.And we have somewhere
So it seems fair (and expected for devs) that all browsers do set the
width
andheight
attributes to0
, since there is no bitmap anymore, even though the normative text seems to make the reference the other way around.However it starts being complicated when setting these attributes. The specs only define what the setters do when the context mode is
2d
, there is nothing about when it'sdetached
, and browsers don't agree.APIs that do consume
OffscreenCanvas
go through check the usability of the image argument which does throw when the image's width or height is zero, so Chrome's behavior looks very surprising.Between Firefox's and Safari's behavior, I personally do not have any preferences, but I think we should specify one.
Of note,
OffscreenCanvas
on which we set the width and height, fromcreateImageBitmap()
the message is "The ImageBitmap could not be allocated." and fromdrawImage()
"The image source is detached".Safari is happy drawing a transferred
OffscreenCanvas
(observable with compositing), but this is probably a browser bug since the image's dimensions should still be zero (BUG 266918).Another point the specs don't handle currently is what happens to the placeholder
<canvas>
of such a detachedOffscreenCanvas
.I suppose the reference should be removed from the object in the transfer steps. For this one I could only think of the aforementioned size setters as a way to check if the reference held, in Chrome the placeholder isn't modified, Firefox throws on these anyway, and in Safari it's an apparent noop.
cc @whatwg/canvas