2018-11-22 16:21:55 +00:00
|
|
|
/*
|
2024-09-06 15:44:31 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2020-01-17 18:27:37 -07:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
2024-09-06 15:44:31 +01:00
|
|
|
Copyright 2018 New Vector Ltd
|
2018-11-22 16:21:55 +00:00
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-06 15:44:31 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2018-11-22 16:21:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Separate file that sets up rageshake logging when imported.
|
|
|
|
|
* This is necessary so that rageshake logging is set up before
|
|
|
|
|
* anything else. Webpack puts all import statements at the top
|
|
|
|
|
* of the file before any code, so imports will always be
|
|
|
|
|
* evaluated first. Other imports can cause other code to be
|
|
|
|
|
* evaluated (eg. the loglevel library in js-sdk, which if set
|
|
|
|
|
* up before rageshake causes some js-sdk logging to be missing
|
|
|
|
|
* from the rageshake.)
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-15 16:56:22 +02:00
|
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
|
|
|
|
|
2024-10-15 14:57:26 +01:00
|
|
|
import * as rageshake from "../rageshake/rageshake";
|
|
|
|
|
import SdkConfig from "../SdkConfig";
|
2026-01-20 12:29:18 +00:00
|
|
|
import sendBugReport, { loadBugReport } from "../rageshake/submit-rageshake";
|
|
|
|
|
import { BugReportEndpointURLLocal } from "../IConfigOptions";
|
2024-10-15 14:57:26 +01:00
|
|
|
|
2022-11-23 17:24:36 +01:00
|
|
|
export function initRageshake(): Promise<void> {
|
2021-03-16 14:21:59 -06:00
|
|
|
// we manually check persistence for rageshakes ourselves
|
|
|
|
|
const prom = rageshake.init(/*setUpPersistence=*/ false);
|
2020-04-05 00:27:59 +01:00
|
|
|
prom.then(
|
2024-06-12 17:17:29 +01:00
|
|
|
async () => {
|
2021-10-15 16:59:13 +02:00
|
|
|
logger.log("Initialised rageshake.");
|
|
|
|
|
logger.log(
|
2023-07-11 23:39:16 +01:00
|
|
|
"To fix line numbers in Chrome: " +
|
|
|
|
|
"Meatball menu → Settings → Ignore list → Add /rageshake\\.ts & /logger\\.ts$",
|
2021-04-15 10:57:54 +01:00
|
|
|
);
|
2018-11-22 16:21:55 +00:00
|
|
|
|
2022-07-11 13:22:37 +01:00
|
|
|
window.addEventListener("beforeunload", () => {
|
2021-10-15 16:59:13 +02:00
|
|
|
logger.log("element-web closing");
|
2018-11-22 16:21:55 +00:00
|
|
|
// try to flush the logs to indexeddb
|
|
|
|
|
rageshake.flush();
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-12 17:17:29 +01:00
|
|
|
await rageshake.cleanup();
|
2018-11-22 16:21:55 +00:00
|
|
|
},
|
|
|
|
|
(err) => {
|
2021-10-15 16:56:22 +02:00
|
|
|
logger.error("Failed to initialise rageshake: " + err);
|
2018-11-22 16:21:55 +00:00
|
|
|
},
|
|
|
|
|
);
|
2020-04-05 00:27:59 +01:00
|
|
|
return prom;
|
2018-11-22 16:21:55 +00:00
|
|
|
}
|
|
|
|
|
|
2022-11-23 17:24:36 +01:00
|
|
|
export function initRageshakeStore(): Promise<void> {
|
2021-03-16 14:21:59 -06:00
|
|
|
return rageshake.tryInitStorage();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-20 12:29:18 +00:00
|
|
|
window.mxSendRageshake = async function (text: string, withLogs = true): Promise<void> {
|
2020-09-15 15:49:25 +01:00
|
|
|
const url = SdkConfig.get().bug_report_endpoint_url;
|
|
|
|
|
if (!url) {
|
2021-10-15 16:56:22 +02:00
|
|
|
logger.error("Cannot send a rageshake - no bug_report_endpoint_url configured");
|
2020-09-15 15:49:25 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-11 12:58:35 -06:00
|
|
|
if (!text || !text.trim()) {
|
2021-10-15 16:56:22 +02:00
|
|
|
logger.error("Cannot send a rageshake without a message - please tell us what went wrong");
|
2019-07-11 12:58:35 -06:00
|
|
|
return;
|
|
|
|
|
}
|
2026-01-20 12:29:18 +00:00
|
|
|
if (url === BugReportEndpointURLLocal) {
|
|
|
|
|
try {
|
|
|
|
|
const tape = await loadBugReport({
|
|
|
|
|
userText: text,
|
|
|
|
|
sendLogs: withLogs,
|
|
|
|
|
progressCallback: logger.log.bind(console),
|
|
|
|
|
});
|
|
|
|
|
const blob = new Blob([new Uint8Array(tape.out)], { type: "application/gzip" });
|
|
|
|
|
const url = URL.createObjectURL(blob);
|
|
|
|
|
logger.log(`Your logs are available at ${url}`);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
logger.error("Failed to load bug report", err);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
await sendBugReport(url, {
|
|
|
|
|
userText: text,
|
|
|
|
|
sendLogs: withLogs,
|
|
|
|
|
progressCallback: logger.log.bind(console),
|
|
|
|
|
});
|
2021-10-15 16:59:13 +02:00
|
|
|
logger.log("Bug report sent!");
|
2026-01-20 12:29:18 +00:00
|
|
|
} catch (err) {
|
|
|
|
|
logger.error("Failed to send bug report", err);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-27 16:11:58 -07:00
|
|
|
};
|