Skip to content

Commit 84e4a9e

Browse files
committed
Add some sustainable logging to the background script.
1 parent 4527693 commit 84e4a9e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/entrypoints/background.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { CommentEvent, CommentSpot } from '@/lib/enhancer'
22
import { type DraftStats, statsFor } from '@/lib/enhancers/draft-stats'
3+
import { logger } from '@/lib/logger'
34
import type { GetTableRowsResponse, ToBackgroundMessage } from '@/lib/messages'
5+
46
import {
57
CLOSE_MESSAGE_PORT,
68
isContentToBackgroundMessage,
@@ -36,6 +38,7 @@ export interface CommentTableRow {
3638
export const openSpots = new Map<string, CommentStorage>()
3739

3840
export function handleCommentEvent(message: CommentEvent, sender: any): boolean {
41+
logger.debug('received comment event', message)
3942
if (
4043
(message.type === 'ENHANCED' || message.type === 'DESTROYED') &&
4144
sender.tab?.id &&
@@ -68,6 +71,7 @@ export function handlePopupMessage(
6871
sendResponse: (response: any) => void,
6972
): typeof CLOSE_MESSAGE_PORT | typeof KEEP_PORT_OPEN {
7073
if (isGetOpenSpotsMessage(message)) {
74+
logger.debug('received open spots message', message)
7175
const rows: CommentTableRow[] = Array.from(openSpots.values()).map((storage) => {
7276
const [time, content] = storage.drafts.at(-1)!
7377
const row: CommentTableRow = {
@@ -87,6 +91,7 @@ export function handlePopupMessage(
8791
sendResponse(response)
8892
return KEEP_PORT_OPEN
8993
} else if (isSwitchToTabMessage(message)) {
94+
logger.debug('received switch tab message', message)
9095
browser.windows
9196
.update(message.windowId, { focused: true })
9297
.then(() => {
@@ -97,6 +102,7 @@ export function handlePopupMessage(
97102
})
98103
return CLOSE_MESSAGE_PORT
99104
} else {
105+
logger.error('received unknown message', message)
100106
throw new Error(`Unhandled popup message type: ${message?.type || 'unknown'}`)
101107
}
102108
}

0 commit comments

Comments
 (0)