mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-13 06:38:48 +02:00
MozReview-Commit-ID: CJtpm8zlLxa --HG-- extra : rebase_source : c6a834d5aaba0f84f5e147333085883de1a118e8
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
/* global content:false, sendAsyncMessage:false */
|
|
|
|
let { utils: Cu } = Components;
|
|
|
|
const TABDATA_MESSAGE = "WebCompat:SendTabData";
|
|
|
|
let getScreenshot = function(win) {
|
|
return new Promise(resolve => {
|
|
let url = win.location.href;
|
|
try {
|
|
let dpr = win.devicePixelRatio;
|
|
let canvas = win.document.createElement("canvas");
|
|
let ctx = canvas.getContext("2d");
|
|
let x = win.document.documentElement.scrollLeft;
|
|
let y = win.document.documentElement.scrollTop;
|
|
let w = win.innerWidth;
|
|
let h = win.innerHeight;
|
|
canvas.width = dpr * w;
|
|
canvas.height = dpr * h;
|
|
ctx.scale(dpr, dpr);
|
|
ctx.drawWindow(win, x, y, w, h, "#fff");
|
|
canvas.toBlob(blob => {
|
|
resolve({url, blob});
|
|
});
|
|
} catch (ex) {
|
|
// CanvasRenderingContext2D.drawWindow can fail depending on memory or
|
|
// surface size. Rather than reject, resolve the URL so the user can
|
|
// file an issue without a screenshot.
|
|
Cu.reportError(`WebCompatReporter: getting a screenshot failed: ${ex}`);
|
|
resolve({url});
|
|
}
|
|
});
|
|
};
|
|
|
|
getScreenshot(content).then(data => sendAsyncMessage(TABDATA_MESSAGE, data));
|