Skip to content

Commit

Permalink
feat: ignore certain messages when logging backend messages (#1742)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xKheops authored Dec 11, 2024
1 parent 32167b2 commit 4c49a13
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/extension-core/src/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ const OBFUSCATE_LOG_MESSAGES: MessageTypes[] = [
]
const OBFUSCATED_PAYLOAD = "#OBFUSCATED#"

// ignore the ones that generate too much spam, making it hard to debug other things
const IGNORED_LOG_MESSAGES: MessageTypes[] = [
"pri(keepalive)",
"pri(keepunlocked)",
"pri(app.analyticsCapture)",
]

const formatFrom = (source: string) => {
if (["extension", "<unknown>"].includes(source)) return source
if (!source) return source
Expand Down Expand Up @@ -60,8 +67,8 @@ const talismanHandler = <TMessageType extends MessageTypes>(
}`
const shouldLog = !OBFUSCATE_LOG_MESSAGES.includes(message)

// eslint-disable-next-line no-console
log.debug(`[${port.name} REQ] ${source}`, { request: shouldLog ? request : OBFUSCATED_PAYLOAD })
if (!IGNORED_LOG_MESSAGES.includes(message))
log.debug(`[${port.name} REQ] ${source}`, { request: shouldLog ? request : OBFUSCATED_PAYLOAD })

const safePostMessage = (port: chrome.runtime.Port | undefined, message: unknown): void => {
// only send message back to port if it's still connected, unfortunately this check is not reliable in all browsers
Expand All @@ -87,10 +94,11 @@ const talismanHandler = <TMessageType extends MessageTypes>(
// resolve the promise and send back the response
promise
.then((response): void => {
log.debug(`[${port.name} RES] ${source}`, {
request: shouldLog ? request : OBFUSCATED_PAYLOAD,
response: shouldLog ? response : OBFUSCATED_PAYLOAD,
})
if (!IGNORED_LOG_MESSAGES.includes(message))
log.debug(`[${port.name} RES] ${source}`, {
request: shouldLog ? request : OBFUSCATED_PAYLOAD,
response: shouldLog ? response : OBFUSCATED_PAYLOAD,
})

// between the start and the end of the promise, the user may have closed
// the tab, in which case port will be undefined
Expand Down

0 comments on commit 4c49a13

Please sign in to comment.