Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Unified Diff: headless/app/headless_shell.cc

Issue 2000723002: headless: Implement screenshot capturing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | headless/app/headless_shell_switches.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: headless/app/headless_shell.cc
diff --git a/headless/app/headless_shell.cc b/headless/app/headless_shell.cc
index 25c823d541cb196bba2579c004e3722c57d7da3a..d206eb890f8127de691c9c26d3bb6f1122919e6d 100644
--- a/headless/app/headless_shell.cc
+++ b/headless/app/headless_shell.cc
@@ -135,6 +135,9 @@ class HeadlessShell : public HeadlessWebContents::Observer, page::Observer {
<< "Type a Javascript expression to evaluate or \"quit\" to exit."
<< std::endl;
InputExpression();
+ } else if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ headless::switches::kScreenshot)) {
+ CaptureScreenshot();
} else {
Shutdown();
}
@@ -181,6 +184,22 @@ class HeadlessShell : public HeadlessWebContents::Observer, page::Observer {
InputExpression();
}
+ void CaptureScreenshot() {
+ devtools_client_->GetPage()->GetExperimental()->CaptureScreenshot(
+ page::CaptureScreenshotParams::Builder().Build(),
+ base::Bind(&HeadlessShell::OnScreenshotCaptured,
+ base::Unretained(this)));
+ }
+
+ void OnScreenshotCaptured(
+ std::unique_ptr<page::CaptureScreenshotResult> result) {
+ std::unique_ptr<base::Value> value = result->Serialize();
+ std::string result_json;
+ base::JSONWriter::Write(*value, &result_json);
+ std::cout << result_json << std::endl;
+ Shutdown();
+ }
+
bool RemoteDebuggingEnabled() const {
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
« no previous file with comments | « no previous file | headless/app/headless_shell_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698