From ddb15cb19ee2adeee80662ab1292bbbf501a959b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Fri, 4 Feb 2022 14:30:18 +0100 Subject: [PATCH] Bypass rageshake when warning about devtools (#7717) --- src/components/structures/MatrixChat.tsx | 3 ++- src/rageshake/rageshake.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index 19fd89326d..ea951b45ec 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -527,7 +527,8 @@ export default class MatrixChat extends React.PureComponent { "and contribute!", ); - console.log( + global.mx_rage_logger.bypassRageshake( + "log", `%c${waitText}\n%c${scamText}\n%c${devText}`, `font-size:${largeFontSize}; color:blue;`, `font-size:${normalFontSize}; color:red;`, diff --git a/src/rageshake/rageshake.ts b/src/rageshake/rageshake.ts index f275b15a41..5dcf8bc67b 100644 --- a/src/rageshake/rageshake.ts +++ b/src/rageshake/rageshake.ts @@ -45,9 +45,13 @@ const FLUSH_RATE_MS = 30 * 1000; // the length of log data we keep in indexeddb (and include in the reports) const MAX_LOG_SIZE = 1024 * 1024 * 5; // 5 MB +type LogFunction = (...args: (Error | DOMException | object | string)[]) => void; +type LogFunctionName = "log" | "info" | "warn" | "error"; + // A class which monkey-patches the global console and stores log lines. export class ConsoleLogger { private logs = ""; + private originalFunctions: {[key in LogFunctionName]?: LogFunction} = {}; public monkeyPatch(consoleObj: Console): void { // Monkey-patch console logging @@ -60,6 +64,7 @@ export class ConsoleLogger { Object.keys(consoleFunctionsToLevels).forEach((fnName) => { const level = consoleFunctionsToLevels[fnName]; const originalFn = consoleObj[fnName].bind(consoleObj); + this.originalFunctions[fnName] = originalFn; consoleObj[fnName] = (...args) => { this.log(level, ...args); originalFn(...args); @@ -67,6 +72,13 @@ export class ConsoleLogger { }); } + public bypassRageshake( + fnName: LogFunctionName, + ...args: (Error | DOMException | object | string)[] + ): void { + this.originalFunctions[fnName](...args); + } + private log(level: string, ...args: (Error | DOMException | object | string)[]): void { // We don't know what locale the user may be running so use ISO strings const ts = new Date().toISOString();