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

Unified Diff: third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeView.js

Issue 2612913002: DevTools: Add feature to capture full-height screenshots (Closed)
Patch Set: More readable Created 3 years, 11 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
Index: third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeView.js
diff --git a/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeView.js b/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeView.js
index e554590f7ba4a7bd9af511f32418a3ecd1fc4bf2..bd1495dad53a66520cea358bb97f843c15f85e88 100644
--- a/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeView.js
+++ b/third_party/WebKit/Source/devtools/front_end/emulation/DeviceModeView.js
@@ -470,6 +470,47 @@ Emulation.DeviceModeView = class extends UI.VBox {
}
}
}
+
+ captureFullHeightScreenshot() {
+ var mainTarget = SDK.targetManager.mainTarget();
+ if (!mainTarget)
+ return;
+ SDK.DOMModel.muteHighlight();
+ this._model.captureFullHeightScreenshot(screenshotCaptured.bind(this));
+
+ /**
+ * @param {?Protocol.Error} error
+ * @param {string} content
+ * @this {Emulation.DeviceModeView}
+ */
+ function screenshotCaptured(error, content) {
+ SDK.DOMModel.unmuteHighlight();
+ if (error) {
+ console.error(error);
+ return;
+ }
+ var canvas = createElement('canvas');
+ var pageImage = new Image();
+ pageImage.src = 'data:image/png;base64,' + content;
+ pageImage.onload = () => {
+ var ctx = canvas.getContext('2d');
+ ctx.imageSmoothingEnabled = false;
+ canvas.width = pageImage.width;
+ canvas.height = pageImage.height;
+ ctx.drawImage(pageImage, 0, 0);
+ var url = mainTarget && mainTarget.inspectedURL();
+ var fileName = url ? url.trimURL().removeURLFragment() : '';
+ if (this._model.type() === Emulation.DeviceModeModel.Type.Device)
+ fileName += Common.UIString('(%s)', this._model.device().title);
+ var link = createElement('a');
+ link.download = fileName + '.png';
+ canvas.toBlob(function(blob) {
+ link.href = URL.createObjectURL(blob);
+ link.click();
+ });
+ }
+ }
+ }
};
/**

Powered by Google App Engine
This is Rietveld 408576698