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

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: DevTools: Add feature to capture full-height screenshots 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 ce6aef2fe18dd3a2b95a5b1b6cb15d2951cdaedd..095563abca9ccd51fee2b48ad17bba3cf453d598 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,72 @@ Emulation.DeviceModeView = class extends UI.VBox {
}
}
}
+
+ captureFullHeightScreenshot() {
+ var mainTarget = SDK.targetManager.mainTarget();
+ if (!mainTarget)
+ return;
+ SDK.DOMModel.muteHighlight();
+
+ var executionContext = mainTarget.runtimeModel.defaultExecutionContext();
+ executionContext.evaluate(
+ 'document.scrollingElement.scrollHeight', '', false, true, true, false, false, evaluated.bind(this));
+
+ /**
+ * @param {?SDK.RemoteObject} result
+ * @this {Emulation.DeviceModeView}
+ */
+ function evaluated(result) {
+ var scrollHeight = result.value;
dgozman 2017/01/12 21:49:36 I still think we should expose this through getLay
ahmetemirercin 2017/01/13 01:49:23 Done.
+ mainTarget.pageAgent().getLayoutMetrics((err, layoutViewport, visualViewport) => {
dgozman 2017/01/12 21:49:35 I still think this should be in DeviceModeModel. V
ahmetemirercin 2017/01/13 01:49:23 Done.
+ var promises = [];
+ var scaledScrollHeight = Math.floor(scrollHeight * visualViewport.scale * this._model.scale());
+ promises.push(mainTarget.emulationAgent().forceViewport(0, 0, visualViewport.scale));
+ promises.push(mainTarget.emulationAgent().setDeviceMetricsOverride(
+ 0, 0, this._model.appliedDeviceScaleFactor(), this._model.isMobile(), false, this._model.scale()));
+ promises.push(mainTarget.emulationAgent().setVisibleSize(0, scaledScrollHeight));
+ Promise.all(promises).then(() => {
+ mainTarget.pageAgent().captureScreenshot(screenshotCaptured.bind(this));
+ })
+ })
+ }
+
+ /**
+ * @param {?Protocol.Error} error
+ * @param {string} content
+ * @this {Emulation.DeviceModeView}
+ */
+ function screenshotCaptured(error, content) {
+ mainTarget.emulationAgent().resetViewport();
ahmetemirercin 2017/01/13 01:49:23 This is also done according to comment above.
+ this._model.resetVisibleSize();
+ 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, pageImage.width, pageImage.height);
+ 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