Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stricitfy rageshake #10389

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/rageshake/rageshake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ export class ConsoleLogger {
warn: "W",
error: "E",
} as const;
Object.keys(consoleFunctionsToLevels).forEach((fnName: keyof typeof consoleFunctionsToLevels) => {
const level = consoleFunctionsToLevels[fnName];
const originalFn = consoleObj[fnName].bind(consoleObj);
this.originalFunctions[fnName] = originalFn;
consoleObj[fnName] = (...args) => {
this.log(level, ...args);
originalFn(...args);
};
});
(Object.keys(consoleFunctionsToLevels) as [keyof typeof consoleFunctionsToLevels]).forEach(
(fnName: keyof typeof consoleFunctionsToLevels) => {
const level = consoleFunctionsToLevels[fnName];
const originalFn = consoleObj[fnName].bind(consoleObj);
this.originalFunctions[fnName] = originalFn;
consoleObj[fnName] = (...args) => {
this.log(level, ...args);
originalFn(...args);
};
},
);
}

public bypassRageshake(fnName: LogFunctionName, ...args: (Error | DOMException | object | string)[]): void {
Expand Down Expand Up @@ -261,6 +263,8 @@ export class IndexedDBLogStore {
// Returns: a string representing the concatenated logs for this ID.
// Stops adding log fragments when the size exceeds maxSize
function fetchLogs(id: string, maxSize: number): Promise<string> {
if (!db) return Promise.reject("DB unavailable");

const objectStore = db.transaction("logs", "readonly").objectStore("logs");

return new Promise((resolve, reject) => {
Expand All @@ -287,6 +291,8 @@ export class IndexedDBLogStore {

// Returns: A sorted array of log IDs. (newest first)
function fetchLogIds(): Promise<string[]> {
if (!db) return Promise.reject("DB unavailable");

// To gather all the log IDs, query for all records in logslastmod.
const o = db.transaction("logslastmod", "readonly").objectStore("logslastmod");
return selectQuery(o, undefined, (cursor) => {
Expand All @@ -305,6 +311,8 @@ export class IndexedDBLogStore {
}

function deleteLogs(id: string): Promise<void> {
if (!db) return Promise.reject("DB unavailable");

return new Promise<void>((resolve, reject) => {
const txn = db.transaction(["logs", "logslastmod"], "readwrite");
const o = txn.objectStore("logs");
Expand Down
26 changes: 15 additions & 11 deletions src/rageshake/submit-rageshake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async function collectBugReport(opts: IOpts = {}, gzipLogs = true): Promise<Form
keys.push(`curve25519:${client.getDeviceCurve25519Key()}`);
}
body.append("device_keys", keys.join(", "));
body.append("cross_signing_key", client.getCrossSigningId());
body.append("cross_signing_key", client.getCrossSigningId() ?? "n/a");

// add cross-signing status information
const crossSigning = client.crypto.crossSigningInfo;
Expand All @@ -99,7 +99,7 @@ async function collectBugReport(opts: IOpts = {}, gzipLogs = true): Promise<Form
"cross_signing_supported_by_hs",
String(await client.doesServerSupportUnstableFeature("org.matrix.e2e_cross_signing")),
);
body.append("cross_signing_key", crossSigning.getId());
body.append("cross_signing_key", crossSigning.getId() ?? "n/a");
body.append(
"cross_signing_privkey_in_secret_storage",
String(!!(await crossSigning.isStoredInSecretStorage(secretStorage))),
Expand All @@ -108,15 +108,15 @@ async function collectBugReport(opts: IOpts = {}, gzipLogs = true): Promise<Form
const pkCache = client.getCrossSigningCacheCallbacks();
body.append(
"cross_signing_master_privkey_cached",
String(!!(pkCache && (await pkCache.getCrossSigningKeyCache("master")))),
String(!!(pkCache && (await pkCache?.getCrossSigningKeyCache?.("master")))),
);
body.append(
"cross_signing_self_signing_privkey_cached",
String(!!(pkCache && (await pkCache.getCrossSigningKeyCache("self_signing")))),
String(!!(pkCache && (await pkCache?.getCrossSigningKeyCache?.("self_signing")))),
);
body.append(
"cross_signing_user_signing_privkey_cached",
String(!!(pkCache && (await pkCache.getCrossSigningKeyCache("user_signing")))),
String(!!(pkCache && (await pkCache?.getCrossSigningKeyCache?.("user_signing")))),
);

body.append("secret_storage_ready", String(await client.isSecretStorageReady()));
Expand Down Expand Up @@ -163,14 +163,14 @@ async function collectBugReport(opts: IOpts = {}, gzipLogs = true): Promise<Form
body.append("storageManager_usage", String(estimate.usage));
if (estimate.usageDetails) {
Object.keys(estimate.usageDetails).forEach((k) => {
body.append(`storageManager_usage_${k}`, String(estimate.usageDetails[k]));
body.append(`storageManager_usage_${k}`, String(estimate.usageDetails![k]));
});
}
} catch (e) {}
}

if (window.Modernizr) {
const missingFeatures = Object.keys(window.Modernizr).filter(
const missingFeatures = (Object.keys(window.Modernizr) as [keyof ModernizrStatic]).filter(
(key: keyof ModernizrStatic) => window.Modernizr[key] === false,
);
if (missingFeatures.length > 0) {
Expand Down Expand Up @@ -253,7 +253,7 @@ export async function downloadBugReport(opts: IOpts = {}): Promise<void> {
await new Promise<void>((resolve) => {
const reader = new FileReader();
reader.addEventListener("loadend", (ev) => {
tape.append(`log-${i++}.log`, new TextDecoder().decode(ev.target.result as ArrayBuffer));
tape.append(`log-${i++}.log`, new TextDecoder().decode(reader.result as ArrayBuffer));
resolve();
});
reader.readAsArrayBuffer(value as Blob);
Expand Down Expand Up @@ -302,14 +302,18 @@ export async function submitFeedback(

body.append("app", "element-web");
body.append("version", version || "UNKNOWN");
body.append("platform", PlatformPeg.get().getHumanReadableName());
body.append("user_id", MatrixClientPeg.get()?.getUserId());
body.append("platform", PlatformPeg.get()?.getHumanReadableName() ?? "n/a");
body.append("user_id", MatrixClientPeg.get()?.getUserId() ?? "n/a");

for (const k in extraData) {
body.append(k, JSON.stringify(extraData[k]));
}

await submitReport(SdkConfig.get().bug_report_endpoint_url, body, () => {});
const bugReportEndpointUrl = SdkConfig.get().bug_report_endpoint_url;

if (bugReportEndpointUrl) {
await submitReport(bugReportEndpointUrl, body, () => {});
}
}

function submitReport(endpoint: string, body: FormData, progressCallback: (str: string) => void): Promise<string> {
Expand Down