fune/browser/extensions/webcompat-reporter/content/tab-frame.js
Mike Taylor 069403beb5 Bug 1399987. Send tracking and mixed content blocking status as part of browser details. r=Gijs
This should allow us to more quickly understand when site bustage is TP- or MC-related.

If the tab had tracking content blocked, we capture if the user is using the basic or strict
list, and set a label with that information.

MozReview-Commit-ID: lkkZjo620E

--HG--
extra : rebase_source : 93c679b5f93f69f0c380524d32003e331b9e10b5
2018-04-19 17:36:05 -07:00

43 lines
1.6 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/. */
/* eslint-env mozilla/frame-script */
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({
blob,
hasMixedActiveContentBlocked: docShell.hasMixedActiveContentBlocked,
hasMixedDisplayContentBlocked: docShell.hasMixedDisplayContentBlocked,
url,
hasTrackingContentBlocked: docShell.hasTrackingContentBlocked
});
});
} 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));