WebKit Bugzilla
Attachment 373088 Details for
Bug 199309
: Web Inspector: support `console.screenshot` with detached Nodes that are graphical
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
199309.diff (text/plain), 4.59 KB, created by
Devin Rousso
on 2019-06-27 23:03:42 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Devin Rousso
Created:
2019-06-27 23:03:42 PDT
Size:
4.59 KB
patch
obsolete
>diff --git a/LayoutTests/inspector/console/console-screenshot-expected.txt b/LayoutTests/inspector/console/console-screenshot-expected.txt >index f50e78c5678..cbaf1abc8a3 100644 >--- a/LayoutTests/inspector/console/console-screenshot-expected.txt >+++ b/LayoutTests/inspector/console/console-screenshot-expected.txt >@@ -1,5 +1,6 @@ > CONSOLE MESSAGE: [object HTMLDivElement] > CONSOLE MESSAGE: test >+CONSOLE MESSAGE: [object HTMLImageElement] > CONSOLE MESSAGE: 42 > CONSOLE MESSAGE: Viewport > Tests for the console.screenshot API. >@@ -18,6 +19,12 @@ 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.Node.DetachedScreenshotable >+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.Node.DetachedNonScreenshotable > PASS: Could not capture screenshot > >diff --git a/LayoutTests/inspector/console/console-screenshot.html b/LayoutTests/inspector/console/console-screenshot.html >index 04f6c6652db..064e063273c 100644 >--- a/LayoutTests/inspector/console/console-screenshot.html >+++ b/LayoutTests/inspector/console/console-screenshot.html >@@ -11,6 +11,15 @@ function createDetachedTest() > return div; > } > >+function testHTMLImageElement() { >+ // 2x2 red square >+ let image = document.createElement("img"); >+ image.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAAXNSR0IArs4c6QAAABNJREFUCB1j/M/AAEQMDEwgAgQAHxcCAmtAm/sAAAAASUVORK5CYII="; >+ image.addEventListener("load", async (event) => { >+ console.screenshot(image); >+ }); >+} >+ > function test() > { > let suite = InspectorTest.createAsyncSuite("console.screenshot"); >@@ -69,6 +78,18 @@ function test() > }, > }); > >+ addTest({ >+ name: "console.screenshot.Node.DetachedScreenshotable", >+ expression: `testHTMLImageElement()`, >+ 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.Node.DetachedNonScreenshotable", > expression: `console.screenshot(createDetachedTest())`, >diff --git a/Source/WebCore/page/PageConsoleClient.cpp b/Source/WebCore/page/PageConsoleClient.cpp >index 3f43eb080a6..9e30832ced6 100644 >--- a/Source/WebCore/page/PageConsoleClient.cpp >+++ b/Source/WebCore/page/PageConsoleClient.cpp >@@ -29,6 +29,7 @@ > #include "config.h" > #include "PageConsoleClient.h" > >+#include "CachedImage.h" > #include "CanvasRenderingContext2D.h" > #include "Chrome.h" > #include "ChromeClient.h" >@@ -36,6 +37,8 @@ > #include "Frame.h" > #include "FrameSnapshotting.h" > #include "HTMLCanvasElement.h" >+#include "HTMLImageElement.h" >+#include "Image.h" > #include "ImageBitmapRenderingContext.h" > #include "ImageBuffer.h" > #include "InspectorController.h" >@@ -44,6 +47,7 @@ > #include "JSCanvasRenderingContext2D.h" > #include "JSExecState.h" > #include "JSHTMLCanvasElement.h" >+#include "JSHTMLImageElement.h" > #include "JSImageBitmapRenderingContext.h" > #include "JSNode.h" > #include "JSOffscreenCanvas.h" >@@ -285,7 +289,17 @@ void PageConsoleClient::screenshot(JSC::ExecState* state, Ref<ScriptArguments>&& > // Get new first argument after reordering. > arguments->getFirstArgumentAsString(messageText); > >- if (auto* node = JSNode::toWrapped(state->vm(), target)) { >+ if (auto* imageElement = JSHTMLImageElement::toWrapped(state->vm(), target)) { >+ if (auto* cachedImage = imageElement->cachedImage()) { >+ auto* image = cachedImage->image(); >+ if (image && image != &Image::nullImage()) { >+ auto imageBuffer = ImageBuffer::create(image->size(), RenderingMode::Unaccelerated); >+ imageBuffer->context().drawImage(*image, FloatPoint(0, 0)); >+ dataURL = imageBuffer->toDataURL("image/png"); >+ } >+ } >+ captureAttempted = true; >+ } else if (auto* node = JSNode::toWrapped(state->vm(), target)) { > if (auto snapshot = WebCore::snapshotNode(m_page.mainFrame(), *node)) > dataURL = snapshot->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 199309
:
373088
|
374832
|
374847
|
374852