Bypass rageshake when warning about devtools (#7717)

This commit is contained in:
Šimon Brandner 2022-02-04 14:30:18 +01:00 committed by GitHub
parent 78373e86ea
commit ddb15cb19e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View file

@ -527,7 +527,8 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
"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;`,

View file

@ -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();