Remove logging to browser (#733)

* Don't log to browser console

* Don't log options (too verbose)

---------

Co-authored-by: ekzyis <ek@stacker.news>
This commit is contained in:
ekzyis 2024-01-04 20:53:52 +01:00 committed by GitHub
parent 4d953fc3a9
commit 045ba28c41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 5 deletions

View File

@ -20,8 +20,6 @@ let activeCount = 0
const log = (message, level = 'info', context) => { const log = (message, level = 'info', context) => {
messageChannelPort?.postMessage({ level, message, context }) messageChannelPort?.postMessage({ level, message, context })
if (level === 'error') console.error(message)
else console.log(message)
} }
export function onPush (sw) { export function onPush (sw) {
@ -62,7 +60,7 @@ export function onPush (sw) {
log(`[sw:push] ${nid} - closing existing notifications`) log(`[sw:push] ${nid} - closing existing notifications`)
notifications.filter(({ tag: nTag }) => nTag === tag).forEach(n => n.close()) 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) return await sw.registration.showNotification(payload.title, payload.options)
} }
@ -72,7 +70,7 @@ export function onPush (sw) {
// incoming notification is first notification with this tag // incoming notification is first notification with this tag
log(`[sw:push] ${nid} - no existing ${tag} notifications found`) log(`[sw:push] ${nid} - no existing ${tag} notifications found`)
setAppBadge(sw, ++activeCount) 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) return await sw.registration.showNotification(payload.title, payload.options)
} }
@ -164,7 +162,7 @@ const mergeAndShowNotification = async (sw, payload, currentNotifications, tag,
} }
const options = { icon: payload.options?.icon, tag, data: { url: '/notifications', ...mergedPayload } } 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) return await sw.registration.showNotification(title, options)
} }