diff --git a/Tests/LibWeb/Text/expected/canvas/export.txt b/Tests/LibWeb/Text/expected/canvas/export.txt new file mode 100644 index 0000000000..59ec16ed03 --- /dev/null +++ b/Tests/LibWeb/Text/expected/canvas/export.txt @@ -0,0 +1 @@ +1. "image/png" diff --git a/Tests/LibWeb/Text/input/canvas/export.html b/Tests/LibWeb/Text/input/canvas/export.html new file mode 100644 index 0000000000..68606d35b8 --- /dev/null +++ b/Tests/LibWeb/Text/input/canvas/export.html @@ -0,0 +1,22 @@ + + diff --git a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp index 0969ca77ff..9ab610e96a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp @@ -246,8 +246,12 @@ static ErrorOr serialize_bitmap(Gfx::Bitmap const& bitmap } // https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-todataurl -String HTMLCanvasElement::to_data_url(StringView type, Optional quality) const +String HTMLCanvasElement::to_data_url(StringView type, Optional quality) { + // It is possible the the canvas doesn't have a associated bitmap so create one + if (!bitmap()) + create_bitmap(); + // FIXME: 1. If this canvas element's bitmap's origin-clean flag is set to false, then throw a "SecurityError" DOMException. // 2. If this canvas element's bitmap has no pixels (i.e. either its horizontal dimension or its vertical dimension is zero) @@ -275,6 +279,10 @@ String HTMLCanvasElement::to_data_url(StringView type, Optional quality) // https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-toblob WebIDL::ExceptionOr HTMLCanvasElement::to_blob(JS::NonnullGCPtr callback, StringView type, Optional quality) { + // It is possible the the canvas doesn't have a associated bitmap so create one + if (!bitmap()) + create_bitmap(); + // FIXME: 1. If this canvas element's bitmap's origin-clean flag is set to false, then throw a "SecurityError" DOMException. // 2. Let result be null. diff --git a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.h b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.h index 79d798f13a..a46629bd31 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLCanvasElement.h @@ -33,7 +33,7 @@ public: WebIDL::ExceptionOr set_width(unsigned); WebIDL::ExceptionOr set_height(unsigned); - String to_data_url(StringView type, Optional quality) const; + String to_data_url(StringView type, Optional quality); WebIDL::ExceptionOr to_blob(JS::NonnullGCPtr callback, StringView type, Optional quality); void present(); diff --git a/Userland/Libraries/LibWeb/WebDriver/Screenshot.cpp b/Userland/Libraries/LibWeb/WebDriver/Screenshot.cpp index a027410892..b61430c8c8 100644 --- a/Userland/Libraries/LibWeb/WebDriver/Screenshot.cpp +++ b/Userland/Libraries/LibWeb/WebDriver/Screenshot.cpp @@ -24,7 +24,7 @@ namespace Web::WebDriver { // https://w3c.github.io/webdriver/#dfn-encoding-a-canvas-as-base64 -static Response encode_canvas_element(HTML::HTMLCanvasElement const& canvas) +static Response encode_canvas_element(HTML::HTMLCanvasElement& canvas) { // FIXME: 1. If the canvas element’s bitmap’s origin-clean flag is set to false, return error with error code unable to capture screen.