Skip to content

Commit

Permalink
Remove logging to browser (#733)
Browse files Browse the repository at this point in the history
* Don't log to browser console

* Don't log options (too verbose)

---------

Co-authored-by: ekzyis <[email protected]>
  • Loading branch information
ekzyis and ekzyis authored Jan 4, 2024
1 parent 4d953fc commit 045ba28
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions sw/eventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ let activeCount = 0

const log = (message, level = 'info', context) => {
messageChannelPort?.postMessage({ level, message, context })
if (level === 'error') console.error(message)
else console.log(message)
}

export function onPush (sw) {
Expand Down Expand Up @@ -62,7 +60,7 @@ export function onPush (sw) {
log(`[sw:push] ${nid} - closing existing notifications`)
notifications.filter(({ tag: nTag }) => nTag === tag).forEach(n => n.close())
}
log(`[sw:push] ${nid} - show notification: ${payload.title} ${JSON.stringify(payload.options)}`)
log(`[sw:push] ${nid} - show notification with title "${payload.title}"`)
return await sw.registration.showNotification(payload.title, payload.options)
}

Expand All @@ -72,7 +70,7 @@ export function onPush (sw) {
// incoming notification is first notification with this tag
log(`[sw:push] ${nid} - no existing ${tag} notifications found`)
setAppBadge(sw, ++activeCount)
log(`[sw:push] ${nid} - show notification: ${payload.title} ${JSON.stringify(payload.options)}`)
log(`[sw:push] ${nid} - show notification with title "${payload.title}"`)
return await sw.registration.showNotification(payload.title, payload.options)
}

Expand Down Expand Up @@ -164,7 +162,7 @@ const mergeAndShowNotification = async (sw, payload, currentNotifications, tag,
}

const options = { icon: payload.options?.icon, tag, data: { url: '/notifications', ...mergedPayload } }
log(`[sw:push] ${nid} - show notification: ${title} ${JSON.stringify(options)}`)
log(`[sw:push] ${nid} - show notification with title "${payload.title}"`)
return await sw.registration.showNotification(title, options)
}

Expand Down

0 comments on commit 045ba28

Please sign in to comment.