Skip to content

feat(site): add webpush notification serviceworker #17123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 27, 2025

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented Mar 26, 2025

Based on #17091

Original changes from https://github.com/coder/coder/commits/kyle/tasks/

  • Improves tests for webpush notifications
  • Sets subscriber correctly in web push payload (without this, notifications do not work in Safari)
    • NOTE: for now, I'm using the Coder Access URL. Some push messaging service don't like it when you use a non-HTTPS URL, so dropping a warn log about this.
  • Adds a service worker and context for push notifications
  • Adds a button beside "Inbox" to enable / disable push notifications

Notes:

  • ✅ Tested in in Firefox and Safari, and Chrome.

@johnstcn johnstcn self-assigned this Mar 26, 2025
@johnstcn johnstcn changed the title site changes from cj/push-notifications-2-rebase WIP feat(site): add webpush notification serviceworker Mar 26, 2025
@johnstcn johnstcn changed the title WIP feat(site): add webpush notification serviceworker WIP: feat(site): add webpush notification serviceworker Mar 26, 2025
@@ -71,6 +79,18 @@ export const NavbarView: FC<NavbarViewProps> = ({
/>
</div>

{enabled ? (
subscribed ? (
<Button variant="outline" disabled={loading} onClick={unsubscribe}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it just for experimental purposes? Dropping a button on NavBar may look inconsistent. If this is permanent, perhaps ask Bruno for his guidance.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, just for experimental. We'll need to better integrate this later.

Base automatically changed from cj/push-notifications-2-rebase to main March 27, 2025 10:03
@johnstcn johnstcn force-pushed the cj/push-notifications-2-site branch from 81b8c6e to 58cc953 Compare March 27, 2025 10:07
@johnstcn johnstcn changed the title WIP: feat(site): add webpush notification serviceworker feat(site): add webpush notification serviceworker Mar 27, 2025
@johnstcn johnstcn requested a review from Copilot March 27, 2025 16:41
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds webpush notification support by implementing a dedicated service worker and integrating related API and UI changes. Key changes include:

  • Bundling and serving the service worker through Vite with proper proxy configuration
  • Implementing the webpush notifications logic, including subscription management via a new React hook and API endpoints
  • Updating tests to verify proper webpush payload handling and functionality

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
site/vite.config.mts Configures service worker bundling and proxy endpoints
site/src/testHelpers/entities.ts Updates mock build info to include a webpush public key
site/src/serviceWorker.ts Implements service worker logic for push and notification click events
site/src/modules/dashboard/Navbar/NavbarView.tsx Adds buttons to enable/disable webpush notifications
site/src/index.tsx Registers the service worker for push notifications
site/src/contexts/useWebpushNotifications.ts Implements a hook for managing webpush subscriptions
site/src/api/api.ts Introduces API methods for creating and deleting webpush subscriptions
coderd/webpush/webpush_test.go Updates tests with random notifications and payload assertions
coderd/webpush/webpush.go Modifies the dispatcher to include a VAPID subscriber and logs errors with endpoint details
coderd/coderdtest/coderdtest.go Updates test setup for the webpush dispatcher with the proper subscriber URL
cli/server.go Integrates a check for HTTPS access URLs before initializing webpush notifications
Comments suppressed due to low confidence (1)

coderd/webpush/webpush_test.go:239

  • [nitpick] The parameters for assert.Equal are inverted. Swap the arguments so that the expected value comes first to improve error messages and consistency.
assert.Equal(t, r.Header.Get("content-encoding"), "aes128gcm")

@johnstcn johnstcn merged commit e1f27a7 into main Mar 27, 2025
39 checks passed
@johnstcn johnstcn deleted the cj/push-notifications-2-site branch March 27, 2025 17:30
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2025
@stirby
Copy link
Collaborator

stirby commented Apr 1, 2025

/cherry-pick release/2.21

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants