Skip to content

Window::create_image_bitmap_with_canvas_rendering_context_2d throws error #3227

Closed
@JohnScience

Description

@JohnScience

Describe the Bug

I wanted to conveniently create an ImageBitmap from CanvasRenderingContext2d. When I found Window::create_image_bitmap_with_canvas_rendering_context_2d, I expected that it's a convenience method for doing so.

However, when I used it, I received the following error:

TypeError: Failed to execute 'createImageBitmap' on 'Window': The provided value is not of type '(Blob or HTMLCanvasElement or HTMLImageElement or HTMLVideoElement or ImageBitmap or ImageData or OffscreenCanvas or SVGImageElement or VideoFrame)'.

Steps to Reproduce

async fn update_buf_dims_gracefully(
    canvas: &HtmlCanvasElement,
    ctx: &CanvasRenderingContext2d,
    window: &Window,
) {
    let client_width= canvas.client_width();
    let client_height = canvas.client_height();

    let image_bitmap: JsFuture = window.
        create_image_bitmap_with_canvas_rendering_context_2d(ctx)
        .unwrap()
        .into();

    let image_bitmap = image_bitmap.await;
    match image_bitmap {
        Ok(image_bitmap) => { log(&image_bitmap) },
        Err(err) => { log(&err) }
    }

    canvas.set_width(client_width as u32);
    canvas.set_height(client_height as u32);
}

The code above is an incomplete implementation of a function relying on Window::create_image_bitmap_with_canvas_rendering_context_2d.

Expected Behavior

Window::create_image_bitmap_with_canvas_rendering_context_2d should either be removed or be functional

Actual Behavior

Results in an error.

Additional Context

No additional context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions