WebKit Bugzilla
Attachment 373084 Details for
Bug 199304
: Web Inspector: support `console.screenshot` with ImageData and ImageBitmap
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
199304.diff (text/plain), 5.42 KB, created by
Devin Rousso
on 2019-06-27 22:06:56 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Devin Rousso
Created:
2019-06-27 22:06:56 PDT
Size:
5.42 KB
patch
obsolete
>diff --git a/LayoutTests/inspector/console/console-screenshot-expected.txt b/LayoutTests/inspector/console/console-screenshot-expected.txt >index f50e78c5678..0f1b8dcf32d 100644 >--- a/LayoutTests/inspector/console/console-screenshot-expected.txt >+++ b/LayoutTests/inspector/console/console-screenshot-expected.txt >@@ -1,5 +1,7 @@ > CONSOLE MESSAGE: [object HTMLDivElement] > CONSOLE MESSAGE: test >+CONSOLE MESSAGE: [object ImageData] >+CONSOLE MESSAGE: [object ImageBitmap] > CONSOLE MESSAGE: 42 > CONSOLE MESSAGE: Viewport > Tests for the console.screenshot API. >@@ -21,6 +23,18 @@ PASS: The image height should be 2px. > -- Running test case: console.screenshot.Node.DetachedNonScreenshotable > PASS: Could not capture screenshot > >+-- Running test case: console.screenshot.ImageData >+PASS: The added message should be an image. >+PASS: The image should not be empty. >+PASS: The image width should be 2px. >+PASS: The image height should be 2px. >+ >+-- Running test case: console.screenshot.ImageBitmap >+PASS: The added message should be an image. >+PASS: The image should not be empty. >+PASS: The image width should be 2px. >+PASS: The image height should be 2px. >+ > -- Running test case: console.screenshot.NonScreenshotableTarget > PASS: The added message should be an image. > PASS: The image should not be empty. >diff --git a/LayoutTests/inspector/console/console-screenshot.html b/LayoutTests/inspector/console/console-screenshot.html >index 04f6c6652db..4c1cccbb196 100644 >--- a/LayoutTests/inspector/console/console-screenshot.html >+++ b/LayoutTests/inspector/console/console-screenshot.html >@@ -11,6 +11,16 @@ function createDetachedTest() > return div; > } > >+function testImageBitmap() { >+ // 2x2 red square >+ let image = document.createElement("img"); >+ image.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAAXNSR0IArs4c6QAAABNJREFUCB1j/M/AAEQMDEwgAgQAHxcCAmtAm/sAAAAASUVORK5CYII="; >+ image.addEventListener("load", async (event) => { >+ let imageBitmap = await createImageBitmap(image); >+ console.screenshot(imageBitmap); >+ }); >+} >+ > function test() > { > let suite = InspectorTest.createAsyncSuite("console.screenshot"); >@@ -75,6 +85,30 @@ function test() > shouldError: true, > }); > >+ addTest({ >+ name: "console.screenshot.ImageData", >+ expression: `console.screenshot(new ImageData(2, 2))`, >+ async imageMessageAddedCallback(message) { >+ InspectorTest.expectNotEqual(message.messageText, "data:", "The image should not be empty."); >+ >+ let img = await WI.ImageUtilities.promisifyLoad(message.messageText); >+ InspectorTest.expectEqual(img.width, 2, "The image width should be 2px."); >+ InspectorTest.expectEqual(img.height, 2, "The image height should be 2px."); >+ }, >+ }); >+ >+ addTest({ >+ name: "console.screenshot.ImageBitmap", >+ expression: `testImageBitmap()`, >+ async imageMessageAddedCallback(message) { >+ InspectorTest.expectNotEqual(message.messageText, "data:", "The image should not be empty."); >+ >+ let img = await WI.ImageUtilities.promisifyLoad(message.messageText); >+ InspectorTest.expectEqual(img.width, 2, "The image width should be 2px."); >+ InspectorTest.expectEqual(img.height, 2, "The image height should be 2px."); >+ }, >+ }); >+ > addTest({ > name: "console.screenshot.NonScreenshotableTarget", > expression: `console.screenshot(42)`, >diff --git a/Source/WebCore/page/PageConsoleClient.cpp b/Source/WebCore/page/PageConsoleClient.cpp >index 3f43eb080a6..5802b69c4a2 100644 >--- a/Source/WebCore/page/PageConsoleClient.cpp >+++ b/Source/WebCore/page/PageConsoleClient.cpp >@@ -36,15 +36,19 @@ > #include "Frame.h" > #include "FrameSnapshotting.h" > #include "HTMLCanvasElement.h" >+#include "ImageBitmap.h" > #include "ImageBitmapRenderingContext.h" > #include "ImageBuffer.h" >+#include "ImageData.h" > #include "InspectorController.h" > #include "InspectorInstrumentation.h" > #include "IntRect.h" > #include "JSCanvasRenderingContext2D.h" > #include "JSExecState.h" > #include "JSHTMLCanvasElement.h" >+#include "JSImageBitmap.h" > #include "JSImageBitmapRenderingContext.h" >+#include "JSImageData.h" > #include "JSNode.h" > #include "JSOffscreenCanvas.h" > #include "Node.h" >@@ -289,6 +293,18 @@ void PageConsoleClient::screenshot(JSC::ExecState* state, Ref<ScriptArguments>&& > if (auto snapshot = WebCore::snapshotNode(m_page.mainFrame(), *node)) > dataURL = snapshot->toDataURL("image/png"_s, WTF::nullopt, PreserveResolution::Yes); > captureAttempted = true; >+ } else if (auto* imageData = JSImageData::toWrapped(state->vm(), target)) { >+ auto sourceSize = imageData->size(); >+ if (auto imageBuffer = ImageBuffer::create(sourceSize, RenderingMode::Unaccelerated)) { >+ IntRect sourceRect(IntPoint(), sourceSize); >+ imageBuffer->putByteArray(*imageData->data(), AlphaPremultiplication::Unpremultiplied, sourceSize, sourceRect, IntPoint()); >+ dataURL = imageBuffer->toDataURL("image/png"_s, WTF::nullopt, PreserveResolution::Yes); >+ } >+ captureAttempted = true; >+ } else if (auto* imageBitmap = JSImageBitmap::toWrapped(state->vm(), target)) { >+ if (auto* imageBuffer = imageBitmap->buffer()) >+ dataURL = imageBuffer->toDataURL("image/png"_s, WTF::nullopt, PreserveResolution::Yes); >+ captureAttempted = true; > } > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 199304
:
373084
|
374822
|
374834
|
374846