WebKit Bugzilla
Attachment 373087 Details for
Bug 199307
: Web Inspector: support `console.screenshot` with dataURL strings
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
199307.diff (text/plain), 4.80 KB, created by
Devin Rousso
on 2019-06-27 22:51:18 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Devin Rousso
Created:
2019-06-27 22:51:18 PDT
Size:
4.80 KB
patch
obsolete
>diff --git a/LayoutTests/inspector/console/console-screenshot-expected.txt b/LayoutTests/inspector/console/console-screenshot-expected.txt >index f50e78c5678..2ef5ab3b953 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: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAAXNSR0IArs4c6QAAABNJREFUCB1j/M/AAEQMDEwgAgQAHxcCAmtAm/sAAAAASUVORK5CYII= >+CONSOLE MESSAGE: test > 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.String.ValidBase64 >+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.String.InvalidBase64 >+PASS: The added message should be an image. >+PASS: The image should not be empty. >+PASS: The image width should be greater than 2px. >+PASS: The image height should be greater than 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..e746ec4b0a9 100644 >--- a/LayoutTests/inspector/console/console-screenshot.html >+++ b/LayoutTests/inspector/console/console-screenshot.html >@@ -75,6 +75,30 @@ function test() > shouldError: true, > }); > >+ addTest({ >+ name: "console.screenshot.String.ValidBase64", >+ expression: `console.screenshot("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAAXNSR0IArs4c6QAAABNJREFUCB1j/M/AAEQMDEwgAgQAHxcCAmtAm/sAAAAASUVORK5CYII=")`, // 2x2 red square >+ 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 than 2px."); >+ InspectorTest.expectEqual(img.height, 2, "The image height should be than 2px."); >+ }, >+ }); >+ >+ addTest({ >+ name: "console.screenshot.String.InvalidBase64", >+ expression: `console.screenshot("test")`, >+ async imageMessageAddedCallback(message) { >+ InspectorTest.expectNotEqual(message.messageText, "data:", "The image should not be empty."); >+ >+ let img = await WI.ImageUtilities.promisifyLoad(message.messageText); >+ InspectorTest.expectGreaterThan(img.width, 2, "The image width should be greater than 2px."); >+ InspectorTest.expectGreaterThan(img.height, 2, "The image height should be greater than 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..14d7eb078d6 100644 >--- a/Source/WebCore/page/PageConsoleClient.cpp >+++ b/Source/WebCore/page/PageConsoleClient.cpp >@@ -57,6 +57,7 @@ > #include <JavaScriptCore/ScriptArguments.h> > #include <JavaScriptCore/ScriptCallStack.h> > #include <JavaScriptCore/ScriptCallStackFactory.h> >+#include <wtf/text/Base64.h> > #include <wtf/text/WTFString.h> > > #if ENABLE(WEBGL) >@@ -289,6 +290,15 @@ 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 { >+ String base64; >+ if (target.getString(state, base64)) { >+ Vector<char> base64Data; >+ if (base64Decode(base64, base64Data)) { >+ dataURL = base64; >+ captureAttempted = true; >+ } >+ } > } > } > >@@ -302,7 +312,7 @@ void PageConsoleClient::screenshot(JSC::ExecState* state, Ref<ScriptArguments>&& > dataURL = snapshot->toDataURL("image/png"_s, WTF::nullopt, PreserveResolution::Yes); > } > >- if (dataURL.isEmpty()) { >+ if (dataURL.isEmpty() || dataURL == "data:,") { > addMessage(std::make_unique<Inspector::ConsoleMessage>(MessageSource::ConsoleAPI, MessageType::Image, MessageLevel::Error, "Could not capture screenshot"_s, WTFMove(arguments))); > return; > }
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 199307
:
373087
|
376297