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.
|
|
|
|
*/
|
|
|
|
|
2021-10-22 22:23:32 +00:00
|
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
2023-07-19 08:25:38 +00:00
|
|
|
import { Method } from "matrix-js-sdk/src/http-api";
|
2018-04-13 00:34:16 +00:00
|
|
|
|
2023-05-12 11:13:08 +00:00
|
|
|
import type * as Pako from "pako";
|
2021-06-29 12:11:58 +00:00
|
|
|
import { MatrixClientPeg } from "../MatrixClientPeg";
|
2018-04-13 00:34:16 +00:00
|
|
|
import PlatformPeg from "../PlatformPeg";
|
|
|
|
import { _t } from "../languageHandler";
|
2019-12-20 00:45:24 +00:00
|
|
|
import * as rageshake from "./rageshake";
|
2020-01-05 20:52:54 +00:00
|
|
|
import SettingsStore from "../settings/SettingsStore";
|
2021-05-11 14:58:19 +00:00
|
|
|
import SdkConfig from "../SdkConfig";
|
2023-07-19 08:25:38 +00:00
|
|
|
import { getServerVersionFromFederationApi } from "../components/views/dialogs/devtools/ServerInfo";
|
2018-04-13 00:34:16 +00:00
|
|
|
|
2020-04-19 11:06:56 +00:00
|
|
|
interface IOpts {
|
2022-01-26 19:30:45 +00:00
|
|
|
labels?: string[];
|
2020-04-19 11:06:56 +00:00
|
|
|
userText?: string;
|
|
|
|
sendLogs?: boolean;
|
2022-01-13 15:55:25 +00:00
|
|
|
progressCallback?: (s: string) => void;
|
2022-01-26 19:30:45 +00:00
|
|
|
customApp?: string;
|
2022-01-13 15:55:25 +00:00
|
|
|
customFields?: Record<string, string>;
|
2020-04-19 11:06:56 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
async function collectBugReport(opts: IOpts = {}, gzipLogs = true): Promise<FormData> {
|
|
|
|
const progressCallback = opts.progressCallback || ((): void => {});
|
2018-04-13 00:34:16 +00:00
|
|
|
|
|
|
|
progressCallback(_t("Collecting app version information"));
|
2023-02-24 15:28:40 +00:00
|
|
|
let version: string | undefined;
|
2018-04-13 00:34:16 +00:00
|
|
|
try {
|
2023-02-24 15:28:40 +00:00
|
|
|
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
|
|
|
|
2023-02-24 15:28:40 +00:00
|
|
|
const userAgent = window.navigator?.userAgent ?? "UNKNOWN";
|
2018-04-13 00:34:16 +00:00
|
|
|
|
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();
|
|
|
|
|
2021-09-21 15:48:09 +00:00
|
|
|
logger.log("Sending bug report.");
|
2018-04-13 00:34:16 +00:00
|
|
|
|
|
|
|
const body = new FormData();
|
|
|
|
body.append("text", opts.userText || "User did not supply any additional text.");
|
2022-01-26 19:30:45 +00:00
|
|
|
body.append("app", opts.customApp || "element-web");
|
2023-02-24 15:28:40 +00:00
|
|
|
body.append("version", version ?? "UNKNOWN");
|
2018-04-13 00:34:16 +00:00
|
|
|
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
|
|
|
|
2022-01-13 15:55:25 +00:00
|
|
|
if (opts.customFields) {
|
|
|
|
for (const key in opts.customFields) {
|
|
|
|
body.append(key, opts.customFields[key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 00:34:16 +00:00
|
|
|
if (client) {
|
2023-02-15 13:36:22 +00:00
|
|
|
body.append("user_id", client.credentials.userId!);
|
|
|
|
body.append("device_id", client.deviceId!);
|
2018-04-13 00:34:16 +00:00
|
|
|
|
2023-02-06 10:50:34 +00:00
|
|
|
// TODO: make this work with rust crypto
|
|
|
|
if (client.isCryptoEnabled() && client.crypto) {
|
2020-05-11 15:21:08 +00:00
|
|
|
const keys = [`ed25519:${client.getDeviceEd25519Key()}`];
|
|
|
|
if (client.getDeviceCurve25519Key) {
|
|
|
|
keys.push(`curve25519:${client.getDeviceCurve25519Key()}`);
|
|
|
|
}
|
|
|
|
body.append("device_keys", keys.join(", "));
|
2023-05-15 18:30:43 +00:00
|
|
|
body.append("cross_signing_key", (await client.getCrypto()?.getCrossSigningKeyId()) ?? "n/a");
|
2020-05-12 08:44:49 +00:00
|
|
|
|
|
|
|
// add cross-signing status information
|
2021-06-19 18:41:45 +00:00
|
|
|
const crossSigning = client.crypto.crossSigningInfo;
|
|
|
|
const secretStorage = client.crypto.secretStorage;
|
2020-05-12 08:44:49 +00:00
|
|
|
|
2020-09-03 12:43:14 +00:00
|
|
|
body.append("cross_signing_ready", String(await client.isCrossSigningReady()));
|
2023-03-15 17:32:31 +00:00
|
|
|
body.append("cross_signing_key", crossSigning.getId() ?? "n/a");
|
2021-07-07 09:54:21 +00:00
|
|
|
body.append(
|
|
|
|
"cross_signing_privkey_in_secret_storage",
|
2020-05-12 08:44:49 +00:00
|
|
|
String(!!(await crossSigning.isStoredInSecretStorage(secretStorage))),
|
|
|
|
);
|
|
|
|
|
|
|
|
const pkCache = client.getCrossSigningCacheCallbacks();
|
2021-07-07 09:54:21 +00:00
|
|
|
body.append(
|
|
|
|
"cross_signing_master_privkey_cached",
|
2023-03-15 17:32:31 +00:00
|
|
|
String(!!(pkCache && (await pkCache?.getCrossSigningKeyCache?.("master")))),
|
2021-09-21 15:48:09 +00:00
|
|
|
);
|
2021-07-07 09:54:21 +00:00
|
|
|
body.append(
|
|
|
|
"cross_signing_self_signing_privkey_cached",
|
2023-03-15 17:32:31 +00:00
|
|
|
String(!!(pkCache && (await pkCache?.getCrossSigningKeyCache?.("self_signing")))),
|
2021-09-21 15:48:09 +00:00
|
|
|
);
|
2021-07-07 09:54:21 +00:00
|
|
|
body.append(
|
|
|
|
"cross_signing_user_signing_privkey_cached",
|
2023-03-15 17:32:31 +00:00
|
|
|
String(!!(pkCache && (await pkCache?.getCrossSigningKeyCache?.("user_signing")))),
|
2021-09-21 15:48:09 +00:00
|
|
|
);
|
2020-05-12 08:44:49 +00:00
|
|
|
|
2020-09-03 12:43:14 +00:00
|
|
|
body.append("secret_storage_ready", String(await client.isSecretStorageReady()));
|
|
|
|
body.append("secret_storage_key_in_account", String(!!(await secretStorage.hasKey())));
|
|
|
|
|
2020-09-16 11:00:49 +00:00
|
|
|
body.append("session_backup_key_in_secret_storage", String(!!(await client.isKeyBackupKeyStored())));
|
2021-06-02 03:36:28 +00:00
|
|
|
const sessionBackupKeyFromCache = await client.crypto.getSessionBackupPrivateKey();
|
2020-05-12 08:44:49 +00:00
|
|
|
body.append("session_backup_key_cached", String(!!sessionBackupKeyFromCache));
|
|
|
|
body.append("session_backup_key_well_formed", String(sessionBackupKeyFromCache instanceof Uint8Array));
|
2020-04-10 12:33:57 +00:00
|
|
|
}
|
2023-07-19 08:25:38 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
// XXX: This is synapse-specific but better than nothing until MSC support for a server version endpoint
|
|
|
|
const data = await client.http.request<Record<string, any>>(
|
|
|
|
Method.Get,
|
|
|
|
"/server_version",
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
{
|
|
|
|
prefix: "/_synapse/admin/v1",
|
|
|
|
},
|
|
|
|
);
|
|
|
|
Object.keys(data).forEach((key) => {
|
|
|
|
body.append(`matrix_hs_${key}`, data[key]);
|
|
|
|
});
|
|
|
|
} catch {
|
|
|
|
try {
|
|
|
|
// XXX: This relies on the federation listener being delegated via well-known
|
|
|
|
// or at the same place as the client server endpoint
|
|
|
|
const data = await getServerVersionFromFederationApi(client);
|
|
|
|
body.append("matrix_hs_name", data.server.name);
|
|
|
|
body.append("matrix_hs_version", data.server.version);
|
|
|
|
} catch {
|
|
|
|
try {
|
|
|
|
// If that fails we'll hit any endpoint and look at the server response header
|
|
|
|
const res = await window.fetch(client.http.getUrl("/login"), {
|
|
|
|
method: "GET",
|
|
|
|
mode: "cors",
|
|
|
|
});
|
|
|
|
if (res.headers.has("server")) {
|
|
|
|
body.append("matrix_hs_server", res.headers.get("server")!);
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
// Could not determine server version
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-21 15:19:53 +00:00
|
|
|
}
|
|
|
|
|
2022-01-26 19:30:45 +00:00
|
|
|
if (opts.labels) {
|
|
|
|
for (const label of opts.labels) {
|
|
|
|
body.append("label", label);
|
|
|
|
}
|
2019-10-09 10:59:10 +00:00
|
|
|
}
|
|
|
|
|
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) => {
|
2023-03-15 17:32:31 +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) {
|
2023-03-15 17:32:31 +00:00
|
|
|
const missingFeatures = (Object.keys(window.Modernizr) as [keyof ModernizrStatic]).filter(
|
2023-02-13 11:39:16 +00:00
|
|
|
(key: keyof ModernizrStatic) => window.Modernizr[key] === false,
|
|
|
|
);
|
2020-04-09 21:55:28 +00:00
|
|
|
if (missingFeatures.length > 0) {
|
|
|
|
body.append("modernizr_missing_features", missingFeatures.join(", "));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-15 13:36:22 +00:00
|
|
|
body.append("mx_local_settings", localStorage.getItem("mx_local_settings")!);
|
2020-08-21 09:32:51 +00:00
|
|
|
|
2018-04-13 00:34:16 +00:00
|
|
|
if (opts.sendLogs) {
|
2023-05-12 11:13:08 +00:00
|
|
|
let pako: typeof Pako | undefined;
|
|
|
|
if (gzipLogs) {
|
|
|
|
pako = await import("pako");
|
|
|
|
}
|
|
|
|
|
2018-04-13 00:34:16 +00:00
|
|
|
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) {
|
2023-06-01 13:43:24 +00:00
|
|
|
buf = pako!.gzip(buf);
|
2020-08-03 12:42:01 +00:00
|
|
|
}
|
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
|
|
|
|
*
|
2022-01-13 15:55:25 +00:00
|
|
|
* @return {Promise<string>} URL returned by the rageshake server
|
2020-01-16 06:22:31 +00:00
|
|
|
*/
|
2023-03-14 11:09:35 +00:00
|
|
|
export default async function sendBugReport(bugReportEndpoint?: string, opts: IOpts = {}): Promise<string> {
|
2020-01-16 06:22:31 +00:00
|
|
|
if (!bugReportEndpoint) {
|
|
|
|
throw new Error("No bug report endpoint has been set.");
|
|
|
|
}
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
const progressCallback = opts.progressCallback || ((): void => {});
|
2020-01-16 06:22:31 +00:00
|
|
|
const body = await collectBugReport(opts);
|
|
|
|
|
2020-08-18 16:38:10 +00:00
|
|
|
progressCallback(_t("Uploading logs"));
|
2022-05-03 21:04:37 +00:00
|
|
|
return submitReport(bugReportEndpoint, body, progressCallback);
|
2018-04-13 00:34:16 +00:00
|
|
|
}
|
|
|
|
|
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).
|
|
|
|
*/
|
2023-01-12 13:25:14 +00:00
|
|
|
export async function downloadBugReport(opts: IOpts = {}): Promise<void> {
|
2023-05-12 11:13:08 +00:00
|
|
|
const Tar = (await import("tar-js")).default;
|
2023-01-12 13:25:14 +00:00
|
|
|
const progressCallback = opts.progressCallback || ((): void => {});
|
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") {
|
2021-01-20 13:40:46 +00:00
|
|
|
await new Promise<void>((resolve) => {
|
2020-01-16 06:22:31 +00:00
|
|
|
const reader = new FileReader();
|
|
|
|
reader.addEventListener("loadend", (ev) => {
|
2023-03-15 17:32:31 +00:00
|
|
|
tape.append(`log-${i++}.log`, new TextDecoder().decode(reader.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 {
|
2023-02-07 10:08:10 +00:00
|
|
|
metadata += `${key} = ${value as string}\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
|
2023-02-13 11:39:16 +00:00
|
|
|
function uint8ToString(buf: Uint8Array): string {
|
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;
|
|
|
|
}
|
|
|
|
|
2021-06-16 08:01:13 +00:00
|
|
|
export async function submitFeedback(
|
2023-04-28 08:45:36 +00:00
|
|
|
label: string | undefined,
|
2021-06-16 08:01:13 +00:00
|
|
|
comment: string,
|
|
|
|
canContact = false,
|
2023-03-15 16:53:49 +00:00
|
|
|
extraData: Record<string, any> = {},
|
2023-01-12 13:25:14 +00:00
|
|
|
): Promise<void> {
|
2023-02-15 13:36:22 +00:00
|
|
|
let version: string | undefined;
|
2021-05-11 14:58:19 +00:00
|
|
|
try {
|
2023-02-15 13:36:22 +00:00
|
|
|
version = await PlatformPeg.get()?.getAppVersion();
|
2021-05-11 14:58:19 +00:00
|
|
|
} catch (err) {} // PlatformPeg already logs this.
|
|
|
|
|
|
|
|
const body = new FormData();
|
2023-04-28 08:45:36 +00:00
|
|
|
if (label) body.append("label", label);
|
2021-05-11 14:58:19 +00:00
|
|
|
body.append("text", comment);
|
2021-05-11 16:30:33 +00:00
|
|
|
body.append("can_contact", canContact ? "yes" : "no");
|
2021-05-11 14:58:19 +00:00
|
|
|
|
|
|
|
body.append("app", "element-web");
|
2023-02-15 13:36:22 +00:00
|
|
|
body.append("version", version || "UNKNOWN");
|
2023-03-15 17:32:31 +00:00
|
|
|
body.append("platform", PlatformPeg.get()?.getHumanReadableName() ?? "n/a");
|
|
|
|
body.append("user_id", MatrixClientPeg.get()?.getUserId() ?? "n/a");
|
2021-05-11 14:58:19 +00:00
|
|
|
|
2021-06-16 08:01:13 +00:00
|
|
|
for (const k in extraData) {
|
2021-11-30 18:08:46 +00:00
|
|
|
body.append(k, JSON.stringify(extraData[k]));
|
2021-06-16 08:01:13 +00:00
|
|
|
}
|
|
|
|
|
2023-03-15 17:32:31 +00:00
|
|
|
const bugReportEndpointUrl = SdkConfig.get().bug_report_endpoint_url;
|
|
|
|
|
|
|
|
if (bugReportEndpointUrl) {
|
|
|
|
await submitReport(bugReportEndpointUrl, body, () => {});
|
|
|
|
}
|
2021-05-11 14:58:19 +00:00
|
|
|
}
|
|
|
|
|
2022-01-13 15:55:25 +00:00
|
|
|
function submitReport(endpoint: string, body: FormData, progressCallback: (str: string) => void): Promise<string> {
|
|
|
|
return new Promise<string>((resolve, reject) => {
|
2019-11-12 11:40:38 +00:00
|
|
|
const req = new XMLHttpRequest();
|
|
|
|
req.open("POST", endpoint);
|
2022-01-13 15:55:25 +00:00
|
|
|
req.responseType = "json";
|
2019-11-12 11:40:38 +00:00
|
|
|
req.timeout = 5 * 60 * 1000;
|
2023-01-12 13:25:14 +00:00
|
|
|
req.onreadystatechange = function (): void {
|
2019-11-12 11:40:38 +00:00
|
|
|
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;
|
|
|
|
}
|
2022-01-13 15:55:25 +00:00
|
|
|
resolve(req.response.report_url || "");
|
2019-11-12 11:40:38 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
req.send(body);
|
|
|
|
});
|
2018-04-13 00:34:16 +00:00
|
|
|
}
|