[GH-ISSUE #112] Remove https restriction for notifications #75

Closed
opened 2026-03-15 12:24:32 +03:00 by kerem · 4 comments
Owner

Originally created by @jonaskuske on GitHub (May 22, 2023).
Original GitHub issue: https://github.com/axllent/mailpit/issues/112

Notifications should also work on localhost, but since mailpit doesn't rely on the browser to check whether notifications are supported or not but instead does its own https verification, the option does not show up in the UI. Would be nice to remove this artifical restriction, happy to contribute! :)

Originally created by @jonaskuske on GitHub (May 22, 2023). Original GitHub issue: https://github.com/axllent/mailpit/issues/112 Notifications should also work on localhost, but since mailpit doesn't rely on the browser to check whether notifications are supported or not but instead does its own https verification, the option does not show up in the UI. Would be nice to remove this artifical restriction, happy to contribute! :)
kerem closed this issue 2026-03-15 12:24:38 +03:00
Author
Owner

@axllent commented on GitHub (May 22, 2023):

Hi @jonaskuske. Actually the HTTPS requirement for notifications is a browser restriction, not a Mailpit one. I simply detect the HTTPS state to show/hide the subscription button (to the notifications) to prevent user confusion and browser warnings.

Where did you get your "should also work on localhost" information from?

<!-- gh-comment-id:1557862898 --> @axllent commented on GitHub (May 22, 2023): Hi @jonaskuske. Actually the HTTPS requirement for notifications is a [browser restriction](https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API), not a Mailpit one. I simply detect the HTTPS state to show/hide the subscription button (to the notifications) to prevent user confusion and browser warnings. Where did you get your "should also work on localhost" information from?
Author
Owner

@jonaskuske commented on GitHub (May 22, 2023):

On MDN itself! The page you linked has a link to secure contexts right at the top, which says this:

image

to show/hide the subscription button (to the notifications) to prevent user confusion and browser warnings

Makes absolute sense! I thought this would work just the same without the https check, as Notification.permission === "denied" on insecure contexts. However, turns out this is only the case on Chrome and Safari, in Firefox it is "default", so permission state isn't enough to determine support there. You can replace the https check with the well-supported property isSecureContext, though:

this.notificationsSupported = window.isSecureContext
  && ("Notification" in window && Notification.permission !== "denied");
<!-- gh-comment-id:1558033751 --> @jonaskuske commented on GitHub (May 22, 2023): On MDN itself! The page you linked has a link to [`secure contexts`](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts) right at the top, which says this: ![image](https://github.com/axllent/mailpit/assets/30421456/c07bf07f-d0f0-4017-ba6b-639d774d5101) > to show/hide the subscription button (to the notifications) to prevent user confusion and browser warnings Makes absolute sense! I thought this would work just the same without the https check, as `Notification.permission === "denied"` on insecure contexts. However, turns out this is only the case on Chrome and Safari, in Firefox it is `"default"`, so permission state isn't enough to determine support there. You can replace the `https` check with the well-supported property `isSecureContext`, though: ```js this.notificationsSupported = window.isSecureContext && ("Notification" in window && Notification.permission !== "denied"); ```
Author
Owner

@axllent commented on GitHub (May 23, 2023):

You're absolutely correct, I did not realise localhost was exempt from HTTPS! Thanks, I've merged your PR. Now I need to make a couple of minor adjustments to related things (including URl displayed in the CLI and in-browser new mail notifications). I appreciate the info and effort, thank you.

<!-- gh-comment-id:1558464235 --> @axllent commented on GitHub (May 23, 2023): You're absolutely correct, I did not realise `localhost` was exempt from HTTPS! Thanks, I've merged your PR. Now I need to make a couple of minor adjustments to related things (including URl displayed in the CLI and in-browser new mail notifications). I appreciate the info and effort, thank you.
Author
Owner

@axllent commented on GitHub (May 26, 2023):

I have just released this as part of v1.6.11 - sorry it took so long, I had a very busy week!

<!-- gh-comment-id:1564224257 --> @axllent commented on GitHub (May 26, 2023): I have just released this as part of v1.6.11 - sorry it took so long, I had a very busy week!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/mailpit#75
No description provided.