1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
/* 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/. */
"use strict";
/* globals browser */
const Config = {
newIssueEndpoint: "https://webcompat.com/issues/new",
newIssueEndpointPref: "newIssueEndpoint",
screenshotFormat: {
format: "jpeg",
quality: 75,
},
};
const FRAMEWORK_KEYS = ["hasFastClick", "hasMobify", "hasMarfeel"];
browser.helpMenu.onHelpMenuCommand.addListener(tab => {
return getWebCompatInfoForTab(tab).then(
info => {
return openWebCompatTab(info);
},
err => {
console.error("WebCompat Reporter: unexpected error", err);
}
);
});
browser.aboutConfigPrefs.onEndpointPrefChange.addListener(checkEndpointPref);
checkEndpointPref();
async function checkEndpointPref() {
const value = await browser.aboutConfigPrefs.getEndpointPref();
if (value === undefined) {
browser.aboutConfigPrefs.setEndpointPref(Config.newIssueEndpoint);
} else {
Config.newIssueEndpoint = value;
}
}
function hasFastClickPageScript() {
const win = window.wrappedJSObject;
if (win.FastClick) {
return true;
}
for (const property in win) {
try {
const proto = win[property].prototype;
if (proto && proto.needsClick) {
return true;
}
} catch (_) {}
}
return false;
}
function hasMobifyPageScript() {
const win = window.wrappedJSObject;
return !!(win.Mobify && win.Mobify.Tag);
}
function hasMarfeelPageScript() {
const win = window.wrappedJSObject;
return !!win.marfeel;
}
function checkForFrameworks(tabId) {
return browser.tabs
.executeScript(tabId, {
code: `
(function() {
${hasFastClickPageScript};
${hasMobifyPageScript};
${hasMarfeelPageScript};
const result = {
hasFastClick: hasFastClickPageScript(),
hasMobify: hasMobifyPageScript(),
hasMarfeel: hasMarfeelPageScript(),
}
return result;
})();
`,
})
.then(([results]) => results)
.catch(() => false);
}
function getWebCompatInfoForTab(tab) {
const { id, url } = tab;
return Promise.all([
browser.browserInfo.getBlockList(),
browser.browserInfo.getBuildID(),
browser.browserInfo.getGraphicsPrefs(),
browser.browserInfo.getUpdateChannel(),
browser.browserInfo.hasTouchScreen(),
browser.tabExtras.getWebcompatInfo(id),
checkForFrameworks(id),
browser.tabs.captureTab(id, Config.screenshotFormat).catch(e => {
console.error("WebCompat Reporter: getting a screenshot failed", e);
return Promise.resolve(undefined);
}),
]).then(
([
blockList,
buildID,
graphicsPrefs,
channel,
hasTouchScreen,
frameInfo,
frameworks,
screenshot,
]) => {
if (channel !== "linux") {
delete graphicsPrefs["layers.acceleration.force-enabled"];
}
const consoleLog = frameInfo.log;
delete frameInfo.log;
return Object.assign(frameInfo, {
tabId: id,
blockList,
details: Object.assign(graphicsPrefs, {
buildID,
channel,
consoleLog,
frameworks,
hasTouchScreen,
"mixed active content blocked":
frameInfo.hasMixedActiveContentBlocked,
"mixed passive content blocked":
frameInfo.hasMixedDisplayContentBlocked,
"tracking content blocked": frameInfo.hasTrackingContentBlocked
? `true (${blockList})`
: "false",
}),
screenshot,
url,
});
}
);
}
function stripNonASCIIChars(str) {
// eslint-disable-next-line no-control-regex
return str.replace(/[^\x00-\x7F]/g, "");
}
async function openWebCompatTab(compatInfo) {
const url = new URL(Config.newIssueEndpoint);
const { details } = compatInfo;
const params = {
url: `${compatInfo.url}`,
utm_source: "desktop-reporter",
utm_campaign: "report-site-issue-button",
src: "desktop-reporter",
details,
extra_labels: [],
};
for (let framework of FRAMEWORK_KEYS) {
if (details.frameworks[framework]) {
params.details[framework] = true;
params.extra_labels.push(
framework.replace(/^has/, "type-").toLowerCase()
);
}
}
delete details.frameworks;
if (details["gfx.webrender.all"] || details["gfx.webrender.enabled"]) {
params.extra_labels.push("type-webrender-enabled");
}
if (compatInfo.hasTrackingContentBlocked) {
params.extra_labels.push(
`type-tracking-protection-${compatInfo.blockList}`
);
}
const json = stripNonASCIIChars(JSON.stringify(params));
const tab = await browser.tabs.create({ url: url.href });
await browser.tabs.executeScript(tab.id, {
runAt: "document_end",
code: `(function() {
async function postMessageData(dataURI, metadata) {
const res = await fetch(dataURI);
const blob = await res.blob();
const data = {
screenshot: blob,
message: metadata
};
postMessage(data, "${url.origin}");
}
postMessageData("${compatInfo.screenshot}", ${json});
})()`,
});
}
|