2018-04-13 00:34:16 +00:00
|
|
|
/*
|
|
|
|
Copyright 2017 OpenMarket Ltd
|
|
|
|
Copyright 2018 New Vector Ltd
|
2019-10-09 10:59:10 +00:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2018-04-13 00:34:16 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import pako from 'pako';
|
|
|
|
|
2019-12-20 21:13:46 +00:00
|
|
|
import {MatrixClientPeg} from '../MatrixClientPeg';
|
2018-04-13 00:34:16 +00:00
|
|
|
import PlatformPeg from '../PlatformPeg';
|
|
|
|
import { _t } from '../languageHandler';
|
2020-01-16 06:22:31 +00:00
|
|
|
import Tar from "tar-js";
|
2018-04-13 00:34:16 +00:00
|
|
|
|
2019-12-20 00:45:24 +00:00
|
|
|
import * as rageshake from './rageshake';
|
2018-04-13 00:34:16 +00:00
|
|
|
|
|
|
|
// polyfill textencoder if necessary
|
|
|
|
import * as TextEncodingUtf8 from 'text-encoding-utf-8';
|
2020-01-05 20:52:54 +00:00
|
|
|
import SettingsStore from "../settings/SettingsStore";
|
2018-04-13 00:34:16 +00:00
|
|
|
let TextEncoder = window.TextEncoder;
|
|
|
|
if (!TextEncoder) {
|
|
|
|
TextEncoder = TextEncodingUtf8.TextEncoder;
|
|
|
|
}
|
|
|
|
|
2020-04-19 11:06:56 +00:00
|
|
|
interface IOpts {
|
|
|
|
label?: string;
|
|
|
|
userText?: string;
|
|
|
|
sendLogs?: boolean;
|
|
|
|
progressCallback?: (string) => void;
|
|
|
|
}
|
|
|
|
|
2020-08-03 12:42:01 +00:00
|
|
|
async function collectBugReport(opts: IOpts = {}, gzipLogs = true) {
|
2018-04-13 00:34:16 +00:00
|
|
|
const progressCallback = opts.progressCallback || (() => {});
|
|
|
|
|
|
|
|
progressCallback(_t("Collecting app version information"));
|
|
|
|
let version = "UNKNOWN";
|
|
|
|
try {
|
|
|
|
version = await PlatformPeg.get().getAppVersion();
|
2018-10-12 03:05:59 +00:00
|
|
|
} catch (err) {} // PlatformPeg already logs this.
|
2018-04-13 00:34:16 +00:00
|
|
|
|
|
|
|
let userAgent = "UNKNOWN";
|
|
|
|
if (window.navigator && window.navigator.userAgent) {
|
|
|
|
userAgent = window.navigator.userAgent;
|
|
|
|
}
|
|
|
|
|
2020-02-14 14:58:37 +00:00
|
|
|
let installedPWA = "UNKNOWN";
|
|
|
|
try {
|
|
|
|
// Known to work at least for desktop Chrome
|
2020-04-19 11:06:56 +00:00
|
|
|
installedPWA = String(window.matchMedia('(display-mode: standalone)').matches);
|
|
|
|
} catch (e) {}
|
2020-02-14 14:58:37 +00:00
|
|
|
|
2020-02-14 17:36:14 +00:00
|
|
|
let touchInput = "UNKNOWN";
|
|
|
|
try {
|
|
|
|
// MDN claims broad support across browsers
|
2020-04-19 11:06:56 +00:00
|
|
|
touchInput = String(window.matchMedia('(pointer: coarse)').matches);
|
2020-02-14 17:36:14 +00:00
|
|
|
} catch (e) { }
|
|
|
|
|
2018-04-13 00:34:16 +00:00
|
|
|
const client = MatrixClientPeg.get();
|
|
|
|
|
|
|
|
console.log("Sending bug report.");
|
|
|
|
|
|
|
|
const body = new FormData();
|
|
|
|
body.append('text', opts.userText || "User did not supply any additional text.");
|
2020-08-06 16:54:52 +00:00
|
|
|
body.append('app', 'element-web');
|
2018-04-13 00:34:16 +00:00
|
|
|
body.append('version', version);
|
|
|
|
body.append('user_agent', userAgent);
|
2020-02-14 14:58:37 +00:00
|
|
|
body.append('installed_pwa', installedPWA);
|
2020-02-14 17:36:14 +00:00
|
|
|
body.append('touch_input', touchInput);
|
2018-04-13 00:34:16 +00:00
|
|
|
|
|
|
|
if (client) {
|
|
|
|
body.append('user_id', client.credentials.userId);
|
|
|
|
body.append('device_id', client.deviceId);
|
|
|
|
|
2020-05-11 15:21:08 +00:00
|
|
|
if (client.isCryptoEnabled()) {
|
|
|
|
const keys = [`ed25519:${client.getDeviceEd25519Key()}`];
|
|
|
|
if (client.getDeviceCurve25519Key) {
|
|
|
|
keys.push(`curve25519:${client.getDeviceCurve25519Key()}`);
|
|
|
|
}
|
|
|
|
body.append('device_keys', keys.join(', '));
|
|
|
|
body.append('cross_signing_key', client.getCrossSigningId());
|
2020-05-12 08:44:49 +00:00
|
|
|
|
|
|
|
body.append('device_keys', keys.join(', '));
|
|
|
|
|
|
|
|
// add cross-signing status information
|
|
|
|
const crossSigning = client._crypto._crossSigningInfo;
|
|
|
|
const secretStorage = client._crypto._secretStorage;
|
|
|
|
|
|
|
|
body.append("cross_signing_key", crossSigning.getId());
|
|
|
|
body.append("cross_signing_pk_in_ssss",
|
|
|
|
String(!!(await crossSigning.isStoredInSecretStorage(secretStorage))));
|
|
|
|
body.append("ssss_key_in_account", String(!!(await secretStorage.hasKey())));
|
|
|
|
|
|
|
|
const pkCache = client.getCrossSigningCacheCallbacks();
|
2020-08-06 14:26:47 +00:00
|
|
|
body.append("master_pk_cached",
|
|
|
|
String(!!(pkCache && await pkCache.getCrossSigningKeyCache("master"))));
|
2020-05-12 08:44:49 +00:00
|
|
|
body.append("self_signing_pk_cached",
|
|
|
|
String(!!(pkCache && await pkCache.getCrossSigningKeyCache("self_signing"))));
|
|
|
|
body.append("user_signing_pk_cached",
|
|
|
|
String(!!(pkCache && await pkCache.getCrossSigningKeyCache("user_signing"))));
|
|
|
|
|
|
|
|
const sessionBackupKeyFromCache = await client._crypto.getSessionBackupPrivateKey();
|
|
|
|
body.append("session_backup_key_cached", String(!!sessionBackupKeyFromCache));
|
|
|
|
body.append("session_backup_key_well_formed", String(sessionBackupKeyFromCache instanceof Uint8Array));
|
|
|
|
body.append("cross_signing_supported_by_hs",
|
|
|
|
String(await client.doesServerSupportUnstableFeature("org.matrix.e2e_cross_signing")));
|
|
|
|
body.append("cross_signing_ready", String(await client.isCrossSigningReady()));
|
2020-08-21 17:22:05 +00:00
|
|
|
body.append("secret_storage_ready", String(await client.isSecretStorageReady()));
|
2020-04-10 12:33:57 +00:00
|
|
|
}
|
2020-02-21 15:19:53 +00:00
|
|
|
}
|
|
|
|
|
2019-10-09 10:59:10 +00:00
|
|
|
if (opts.label) {
|
|
|
|
body.append('label', opts.label);
|
|
|
|
}
|
|
|
|
|
2020-01-05 20:52:54 +00:00
|
|
|
// add labs options
|
2020-08-17 19:37:16 +00:00
|
|
|
const enabledLabs = SettingsStore.getFeatureSettingNames().filter(f => SettingsStore.getValue(f));
|
2020-01-05 20:52:54 +00:00
|
|
|
if (enabledLabs.length) {
|
|
|
|
body.append('enabled_labs', enabledLabs.join(', '));
|
|
|
|
}
|
2020-06-08 10:43:50 +00:00
|
|
|
// if low bandwidth mode is enabled, say so over rageshake, it causes many issues
|
|
|
|
if (SettingsStore.getValue("lowBandwidth")) {
|
|
|
|
body.append("lowBandwidth", "enabled");
|
|
|
|
}
|
2020-01-05 20:52:54 +00:00
|
|
|
|
2020-02-20 00:38:08 +00:00
|
|
|
// add storage persistence/quota information
|
|
|
|
if (navigator.storage && navigator.storage.persisted) {
|
|
|
|
try {
|
2020-04-19 11:06:56 +00:00
|
|
|
body.append("storageManager_persisted", String(await navigator.storage.persisted()));
|
2020-02-20 00:38:08 +00:00
|
|
|
} catch (e) {}
|
2020-03-25 11:07:11 +00:00
|
|
|
} else if (document.hasStorageAccess) { // Safari
|
2020-03-25 11:04:09 +00:00
|
|
|
try {
|
2020-04-19 11:06:56 +00:00
|
|
|
body.append("storageManager_persisted", String(await document.hasStorageAccess()));
|
2020-03-25 11:04:09 +00:00
|
|
|
} catch (e) {}
|
|
|
|
}
|
2020-02-20 00:38:08 +00:00
|
|
|
if (navigator.storage && navigator.storage.estimate) {
|
|
|
|
try {
|
|
|
|
const estimate = await navigator.storage.estimate();
|
2020-04-19 11:06:56 +00:00
|
|
|
body.append("storageManager_quota", String(estimate.quota));
|
|
|
|
body.append("storageManager_usage", String(estimate.usage));
|
2020-02-20 00:38:08 +00:00
|
|
|
if (estimate.usageDetails) {
|
|
|
|
Object.keys(estimate.usageDetails).forEach(k => {
|
2020-04-19 11:06:56 +00:00
|
|
|
body.append(`storageManager_usage_${k}`, String(estimate.usageDetails[k]));
|
2020-02-20 00:38:08 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
|
2020-04-09 21:55:28 +00:00
|
|
|
if (window.Modernizr) {
|
|
|
|
const missingFeatures = Object.keys(window.Modernizr).filter(key => window.Modernizr[key] === false);
|
|
|
|
if (missingFeatures.length > 0) {
|
|
|
|
body.append("modernizr_missing_features", missingFeatures.join(", "));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-21 09:32:51 +00:00
|
|
|
body.append("mx_local_settings", localStorage.getItem('mx_local_settings'));
|
|
|
|
|
2018-04-13 00:34:16 +00:00
|
|
|
if (opts.sendLogs) {
|
|
|
|
progressCallback(_t("Collecting logs"));
|
|
|
|
const logs = await rageshake.getLogsForReport();
|
2018-10-12 03:05:59 +00:00
|
|
|
for (const entry of logs) {
|
2018-04-13 00:34:16 +00:00
|
|
|
// encode as UTF-8
|
2020-08-03 12:42:01 +00:00
|
|
|
let buf = new TextEncoder().encode(entry.lines);
|
2018-04-13 00:34:16 +00:00
|
|
|
|
|
|
|
// compress
|
2020-08-03 12:42:01 +00:00
|
|
|
if (gzipLogs) {
|
|
|
|
buf = pako.gzip(buf);
|
|
|
|
}
|
2018-04-13 00:34:16 +00:00
|
|
|
|
2020-08-03 12:42:01 +00:00
|
|
|
body.append('compressed-log', new Blob([buf]), entry.id);
|
2018-04-13 00:34:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-16 06:22:31 +00:00
|
|
|
return body;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a bug report.
|
|
|
|
*
|
|
|
|
* @param {string} bugReportEndpoint HTTP url to send the report to
|
|
|
|
*
|
|
|
|
* @param {object} opts optional dictionary of options
|
|
|
|
*
|
|
|
|
* @param {string} opts.userText Any additional user input.
|
|
|
|
*
|
|
|
|
* @param {boolean} opts.sendLogs True to send logs
|
|
|
|
*
|
|
|
|
* @param {function(string)} opts.progressCallback Callback to call with progress updates
|
|
|
|
*
|
|
|
|
* @return {Promise} Resolved when the bug report is sent.
|
|
|
|
*/
|
2020-08-03 12:42:01 +00:00
|
|
|
export default async function sendBugReport(bugReportEndpoint: string, opts: IOpts = {}) {
|
2020-01-16 06:22:31 +00:00
|
|
|
if (!bugReportEndpoint) {
|
|
|
|
throw new Error("No bug report endpoint has been set.");
|
|
|
|
}
|
|
|
|
|
|
|
|
const progressCallback = opts.progressCallback || (() => {});
|
|
|
|
const body = await collectBugReport(opts);
|
|
|
|
|
2020-08-18 16:38:10 +00:00
|
|
|
progressCallback(_t("Uploading logs"));
|
2018-04-13 00:34:16 +00:00
|
|
|
await _submitReport(bugReportEndpoint, body, progressCallback);
|
|
|
|
}
|
|
|
|
|
2020-01-16 06:22:31 +00:00
|
|
|
/**
|
|
|
|
* Downloads the files from a bug report. This is the same as sendBugReport,
|
|
|
|
* but instead causes the browser to download the files locally.
|
|
|
|
*
|
|
|
|
* @param {object} opts optional dictionary of options
|
|
|
|
*
|
|
|
|
* @param {string} opts.userText Any additional user input.
|
|
|
|
*
|
|
|
|
* @param {boolean} opts.sendLogs True to send logs
|
|
|
|
*
|
|
|
|
* @param {function(string)} opts.progressCallback Callback to call with progress updates
|
|
|
|
*
|
|
|
|
* @return {Promise} Resolved when the bug report is downloaded (or started).
|
|
|
|
*/
|
2020-08-03 12:42:01 +00:00
|
|
|
export async function downloadBugReport(opts: IOpts = {}) {
|
2020-01-16 06:22:31 +00:00
|
|
|
const progressCallback = opts.progressCallback || (() => {});
|
2020-08-03 12:42:01 +00:00
|
|
|
const body = await collectBugReport(opts, false);
|
2020-01-16 06:22:31 +00:00
|
|
|
|
2020-08-18 16:38:10 +00:00
|
|
|
progressCallback(_t("Downloading logs"));
|
2020-01-16 06:22:31 +00:00
|
|
|
let metadata = "";
|
|
|
|
const tape = new Tar();
|
|
|
|
let i = 0;
|
2020-07-21 21:28:36 +00:00
|
|
|
for (const [key, value] of body.entries()) {
|
|
|
|
if (key === 'compressed-log') {
|
2020-01-16 06:22:31 +00:00
|
|
|
await new Promise((resolve => {
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.addEventListener('loadend', ev => {
|
2020-08-03 12:42:01 +00:00
|
|
|
tape.append(`log-${i++}.log`, new TextDecoder().decode(ev.target.result as ArrayBuffer));
|
2020-01-16 06:22:31 +00:00
|
|
|
resolve();
|
|
|
|
});
|
2020-07-21 21:28:36 +00:00
|
|
|
reader.readAsArrayBuffer(value as Blob);
|
2020-03-30 15:12:28 +00:00
|
|
|
}));
|
2020-01-16 06:22:31 +00:00
|
|
|
} else {
|
2020-07-21 21:28:36 +00:00
|
|
|
metadata += `${key} = ${value}\n`;
|
2020-01-16 06:22:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
tape.append('issue.txt', metadata);
|
|
|
|
|
|
|
|
// We have to create a new anchor to download if we want a filename. Otherwise we could
|
|
|
|
// just use window.open.
|
|
|
|
const dl = document.createElement('a');
|
|
|
|
dl.href = `data:application/octet-stream;base64,${btoa(uint8ToString(tape.out))}`;
|
|
|
|
dl.download = 'rageshake.tar';
|
|
|
|
document.body.appendChild(dl);
|
|
|
|
dl.click();
|
|
|
|
document.body.removeChild(dl);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Source: https://github.com/beatgammit/tar-js/blob/master/examples/main.js
|
2020-07-21 21:28:36 +00:00
|
|
|
function uint8ToString(buf: Buffer) {
|
2020-07-21 21:50:39 +00:00
|
|
|
let out = '';
|
|
|
|
for (let i = 0; i < buf.length; i += 1) {
|
2020-01-16 06:22:31 +00:00
|
|
|
out += String.fromCharCode(buf[i]);
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2020-04-19 11:06:56 +00:00
|
|
|
function _submitReport(endpoint: string, body: FormData, progressCallback: (string) => void) {
|
2019-11-12 11:40:38 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const req = new XMLHttpRequest();
|
|
|
|
req.open("POST", endpoint);
|
|
|
|
req.timeout = 5 * 60 * 1000;
|
|
|
|
req.onreadystatechange = function() {
|
|
|
|
if (req.readyState === XMLHttpRequest.LOADING) {
|
|
|
|
progressCallback(_t("Waiting for response from server"));
|
|
|
|
} else if (req.readyState === XMLHttpRequest.DONE) {
|
|
|
|
// on done
|
|
|
|
if (req.status < 200 || req.status >= 400) {
|
|
|
|
reject(new Error(`HTTP ${req.status}`));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
req.send(body);
|
|
|
|
});
|
2018-04-13 00:34:16 +00:00
|
|
|
}
|