(options: BrowserNotificationOptions)
| 16 | } |
| 17 | |
| 18 | async send(options: BrowserNotificationOptions): Promise<void> { |
| 19 | if (typeof window === "undefined") return; |
| 20 | if (!("Notification" in window)) return; |
| 21 | // Only notify when the tab is in the background |
| 22 | if (!document.hidden) return; |
| 23 | |
| 24 | const granted = await this.requestPermission(); |
| 25 | if (!granted) return; |
| 26 | |
| 27 | const n = new Notification(options.title, { |
| 28 | body: options.body, |
| 29 | icon: "/favicon.ico", |
| 30 | }); |
| 31 | |
| 32 | n.onclick = () => { |
| 33 | window.focus(); |
| 34 | options.onClick?.(); |
| 35 | n.close(); |
| 36 | }; |
| 37 | } |
| 38 | |
| 39 | getPermission(): NotificationPermission { |
| 40 | if (typeof window === "undefined") return "default"; |
nothing calls this directly
no test coverage detected