Skip to content
Open
Changes from 1 commit
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
20 changes: 18 additions & 2 deletions src/background/heartbeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ import { getBucketId, sendHeartbeat } from './client'
import { getEnabled, getHeartbeatData, setHeartbeatData } from '../storage'
import deepEqual from 'deep-equal'

function formatHeartbeatLogData(data: IEvent['data']) {
return Object.entries(data)
.map(([key, value]) => {
const formattedValue =
typeof value === 'string'
? value
: value === undefined
? 'undefined'
: JSON.stringify(value)
Comment on lines +12 to +17

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Unquoted string values may make the log ambiguous when a URL or page title contains the , separator. For example, url=https://example.com, title=Hello, World is hard to parse visually. Wrapping string values in quotes makes field boundaries unambiguous.

Suggested change
const formattedValue =
typeof value === 'string'
? value
: value === undefined
? 'undefined'
: JSON.stringify(value)
const formattedValue =
typeof value === 'string'
? JSON.stringify(value)
: value === undefined
? 'undefined'
: JSON.stringify(value)

return `${key}=${formattedValue}`
})
.join(', ')
}

async function heartbeat(
client: AWClient,
tab: browser.Tabs.Tab | undefined,
Expand Down Expand Up @@ -42,7 +56,9 @@ async function heartbeat(
}
const previousData = await getHeartbeatData()
if (previousData && !deepEqual(previousData, data)) {
console.debug('Sending heartbeat for previous data', previousData)
console.debug(
`Sending heartbeat for previous data: ${formatHeartbeatLogData(previousData)}`,
)
await sendHeartbeat(
client,
await getBucketId(),
Expand All @@ -51,7 +67,7 @@ async function heartbeat(
config.heartbeat.intervalInSeconds + 20,
)
}
console.debug('Sending heartbeat', data)
console.debug(`Sending heartbeat: ${formatHeartbeatLogData(data)}`)
await sendHeartbeat(
client,
await getBucketId(),
Expand Down
Loading